mongodb日期字段string转ISODate

匿名 (未验证) 提交于 2019-12-03 00:22:01

方法一:

var cursor = db.Clinical_laboratory_center_data.find({"article_detial.Registration.Date_of_Last_Refreshed_on": {"$exists": true, "$type": 2 }});  while (cursor.hasNext()) {      var doc = cursor.next();      db.collection.update(         {"_id" : doc._id},          {"$set" : {"article_detial.Registration.Date_of_Last_Refreshed_on" : new ISODate(doc.article_detial.Registration.Date_of_Last_Refreshed_on)}}     )  };

只需要把collection的名字和字段换了即可。doc就是代表你当前的记录。

方法二:

db.ClockTime.find().forEach(function(doc) {      doc.ClockInTime=new Date(doc.ClockInTime);     db.ClockTime.save(doc);      })

原理大致同上一个相同,只不过这个效率稍微低一些。

这里稍微说下,在运行之前,先把超时的时间设置的长一点,不然在运行中会中断。


原味来至:https://stackoverflow.com/questions/10942931/converting-string-to-date-in-mongodb

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!