Query of changing data type in MongoDb
Sep 18, 2021
db.collection.find().forEach(function (doc1) {
db.collection.update({‘_id’ : doc1._id}, [ { $set: { “field” :String(doc1.field)} } ]);
});
db.collection.find().forEach(function (doc1) {
db.collection.update({‘_id’ : doc1._id}, [ { $set: { “field”:ObjectId(doc1.field)} } ]);
});