方法一:
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