mongodb 的 inplace update

嵌套对象为 hash对象时:

db.getCollection('some').update(
{  _id : Object('dfff')}, // 查询条件
{$set : { "embedded.field001":333}}

}

如果嵌套对象为数组时,要使用 <array>.$.field 形式
db.getCollection('some').update(
{  "embeddedArray.id":11}, // 查询条件
{$set : { "embeddedArray.$.field001":333}}

}

猜你喜欢

转载自dwangel.iteye.com/blog/2346279