MongoDB is "schemaless", and there is no concept of metadata for fields, so there is no way to directly modify field types, because each document's fields have their own types. Based on this situation, you can only traverse all documents and modify the field types one by one. For example, the original document is:
{_id: ObjectId(...), date: "Fri May 20 2016 17:04:27 GMT+0800 (CST)"}
Then you need to traverse this collection and modify the field types one by one
db.coll.forEach(function(doc) {
db.coll.update({_id: doc._id}, {$set: {date: new Date(doc.date)}});
});
MongoDB is "schemaless", and there is no concept of metadata for fields, so there is no way to directly modify field types, because each document's fields have their own types. Based on this situation, you can only traverse all documents and modify the field types one by one. For example, the original document is:
Then you need to traverse this collection and modify the field types one by one
$type: is the type. 2 is string type.
Refer to this https://zhuanlan.zhihu.com/p/... to solve UTCDatetime