如何更新mongodb中的子对象
我想用mongodb存储这样的对象:如何更新mongodb中的子对象,mongodb,mongojs,Mongodb,Mongojs,我想用mongodb存储这样的对象: { field: 'example', attr: { tmp : 'test', tmp1 : 'test1' } }; 现在我想搜索具有属性字段的条目:'example',并向其attr对象添加一个字段。如何在mongojs中执行此操作?您可以将tmp2:'test2'值添加到集合中,如下所示 db.myObject.update({field:'example'},{$set:{'a
{
field: 'example',
attr: {
tmp : 'test',
tmp1 : 'test1'
}
};
现在我想搜索具有属性
字段的条目:'example'
,并向其attr
对象添加一个字段。如何在mongojs中执行此操作?您可以将tmp2:'test2'
值添加到集合中,如下所示
db.myObject.update({field:'example'},{$set:{'attr.tmp2':'test2'}})
更新({field:'example'},{$set:{'attr.tmp2':'test2'},{upsert:true})