鍍金池/ 問答/數(shù)據(jù)庫/ 如何更新mongoDB 數(shù)組里對象的多個數(shù)值

如何更新mongoDB 數(shù)組里對象的多個數(shù)值

我想更新一組數(shù)據(jù)。

"records" : [{
    "_id" : ObjectId("5a2e23c750cafa52eaae710d"),
    "createdTime" : "2017-12-11 14:20",
    "jine" : 1500,
    "beizhu":"This is a test"
},
{
    "_id" : ObjectId("5a2e23c750cafa52eaae710e"),
    "createdTime" : "2017-12-11 14:25",
    "jine" : 1500,
    "beizhu":"This is a test2"
}],

比如我想更新_id為5a2e23c750cafa52eaae710d的所有數(shù)據(jù),假如只更新jine,我懂。

Bill.update({'_id':ObjectId("5a2e23c750cafa52eaae710d")},{$set:{"records.$.jine":200}})  

但是,更新所有數(shù)據(jù),就不明白了,請指教。如果對象鍵值只有2、3項還好說。但是如果,要是多項呢?如果,簡單的更新所有的數(shù)據(jù)?

回答
編輯回答
離夢

已經(jīng)解決了。

2017年2月9日 18:47