2015-05-12 97 views
0

我有数据集作为如何在MongoDB中更新高效的收集字段?

{"id":1,"Timestamp":"Mon, 11 May 2015 07:57:46 GMT","brand":"a"} 
{"id":2,"Timestamp":"Mon, 11 May 2015 08:57:46 GMT","brand":"a"} 

数据的预期结果是

{"id":1,"Timestamp":ISODate("2015-05-11T07:57:46Z"),"brand":"a"} 
{"id":2,"Timestamp":ISODate("2015-05-11T08:57:46Z"),"brand":"b"} 

这意味着我想从字符串中的每个行修改时间戳ISODate 我当前的代码是

db.tmpAll.find().forEach(
    function (a) { 
     a.Timestamp = new Date(a.Timestamp); 
     db.tmpAll2.insert(a); 
    } 
); 

它运行成功,但运行代码需要几分钟时间,它需要创建一个新的集合。有没有有效的方法来做到这一点?

回答

0

您不需要创建新的集合。使用collection.save方法更新您的文档。

db.tmpAll.find().forEach(function(doc){ 
    doc.Timestamp = new Date(doc.Timestamp); 
    db.tmpAll.save(doc); 
})