Add incremental id on documents in a collection

Hi,
One thing came in mind that if we have a collection and in that collection i have multiple documents and there is a field named customerId for example which is null and i want to add something in customerId field. i.e.

/1/
{
“userId” : “u12”
“customerId” : null
“province” : “KPK”
}
/2/
{
“userId” : “u13”
“customerId” : null
“province” : “KPK”
}
/3/
{
“userId” : “u14”
“customerId” : null
“province” : “PUNJAB”
}

And i want to replace all the null with a value, for that i can use $ifNull operator but it will work for online one document at a time(i think) . I want to know that is there is a possibility in MmongoDB to add data in incremental form i.e.

/1/
{
“userId” : “u12”
“customerId” : “c101”
“province” : “KPK”
}
/2/
{
“userId” : “u13”
“customerId” : “c102”
“province” : “KPK”
}
/3/
{
“userId” : “u14”
“customerId” : “c103”
“province” : “PUNJAB”
}

Yes, you can add an id value like “c101" replacing the existing null value. It can be done using an aggregation query (or an update with an aggregation). I am assuming the values are in serial like “c101”, “c102”, “c103”, etc.

on the other hand you may leave the customerId completely out until it is not set and add it as soon as it is available. This can be done with $exist and/or update or an aggregation query

I got you, you are saying that i can replace all the nulls with a value but here throughout the value will be same. what i want is that the customerID should be in incremental form.

It involves generating an array with the range of numbers (e.g., 101, 102, … 999, etc.). Then use this array of numbers and an array of the documents that needs to be updated with the customer id. Iterate the array and merge the document with the corresponding customer number (the number can be concatenated with a prefix “c” to form the id like “c101”). This will get the updated documents in an array (which can be unwound, etc. ).