i want to add a id auto increment in Mongo like MySQL does.
I use the Mongoose Auto Increment Library and this works fine.
My problem is that I was not able to place that ID in the documents already created after implementing the library
In this I created a Query to made this before add that library
db.clients.updateMany({},{$set:{id:0}})
This add the 'id' field in all documents whit 0 as value.
Now I want to add the correct id to all documents, but this query add the same id to all documents.
for(var i=0; i<db.clients.count(); i++){
db.clients.update({},{$set:{id:i}})
}
Someone have any idea what I can do?
I appreciate any response!
via Jhonny Afonso
No comments:
Post a Comment