I want to add to all documents in myCollection a field named "serie" with a serial integer number, for example:
{"_id" : "507f191e810c19239de098db", "name" : "John", "serie" : "1"}
{"_id" : "507f191e810c19729de860ea", "name" : "Dave"}, "serie" : "2"}
{"_id" : "507f191e810c19729de564ou", "name" : "Kate"}, "serie" : "3"}
......
The objectId (_id) is not sexy to display or to remember by humains, so I want to keep it and add an other field 'serie' containing simple, short, and unique numbers to identify every doc, like a serial number. So I tried the following script but I got the same "serie" value in all docs:
for(var i=1; i < 543; i++){
db.myCollection.update({},
{ $set: {"serie": i}},
{ upsert:false, multi: true });
}
Thank you for your help.
_idvalue you show here is a both a Primary key of unique values and is monotonic ( ever increasing ) already?