我想转换这样的对象:
{"1":5,"2":7,"3":0,"4":0,"5":0,"6":0,"7":0,"8":0,"9":0,"10":0,"11":0,"12":0}
Run Code Online (Sandbox Code Playgroud)
成为一组键值对,如下所示:
[[1,5],[2,7],[3,0],[4,0]...].
Run Code Online (Sandbox Code Playgroud)
如何在JavaScript中将对象转换为键值对数组?
我在一个集合中的日期插入不正确,并且是一个简单的"2015-09-10" 字符串格式.
我想更新它们以更正ISO日期格式.
我已尝试使用Mongo进行循环,forEach()但我对如何更新集合中的每个文档都不太了解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);
});
Run Code Online (Sandbox Code Playgroud)
这里缺少什么?