【发布时间】:2016-02-05 10:47:09
【问题描述】:
我在一个集合中插入了错误的日期,并且是简单的"2015-09-10" 字符串 格式。
我想更新它们以更正 ISO 日期格式。
我尝试使用 forEach() 在 Mongo 中循环,但我不太了解 shell 如何更新集合中的每个文档。
到目前为止,我在这一点上:
db.getCollection('schedules').find({}).forEach(function (doc) {
doc.time = new Date( doc.time ).toUTCString();
printjson( doc.time );
// ^ This just prints "Invalid Date"
// Also none of the below work when I try saving them
//doc.save();
//db.getCollection('schedules').save(doc);
});
这里缺少什么?
【问题讨论】:
标签: node.js mongodb mongodb-query