I have a collection that contains around 5000 documents. In each document there is field BrandID that I would like to change from string to MongoDB ObjectID. I have tried following shell command but it only updates first document. I dont get any error at all.
db.getCollection('SGProductRepository').find({ BrandID: {$ne : ""}}).forEach(function(obj) {
obj.BrandID = new ObjectId(obj.BrandID);
db.getCollection('SGProductRepository').save(obj);
})
Any idea why it is not working. I am using RoboMongo as an editor. Thanks