Db. bmdMessage. find ({_ id: {$ type: 2 }}). forEach (function (x) {x. _ idObjectId (x. _ id); db. bmdMessage. save (x) ;}); Note: The _ id type cannot be changed if it is created. Reference: Modify the MongoDB field type official document original address: mongodb changes the data type, thanks to the original author
Db. bmdMessage. find ({'_ id': {$ type: 2 }}). forEach (function (x) {x. _ id = ObjectId (x. _ id); db. bmdMessage. save (x) ;}); Note: The _ id type cannot be changed if it is created. Reference: Modify the MongoDB field type official document original address: mongodb changes the data type, thanks to the original author
Db. bmdMessage. find ({'_ id': {$ type: 2 }}). forEach (function (x) {x. _ id = ObjectId (x. _ id); db. bmdMessage. save (x );});
Note: If the _ id type is created, it cannot be changed.
Refer:
Modify the MongoDB Field Type
Official documentation
Original article address: mongodb changes the data type. Thank you for sharing it with the original author.