mongodb只更新特定的子元素

我的数据库结构如下所示:

{ "_id" : ObjectId("51e66873f6a6600436000001") ,"email" : "asd@asd.de", ,"attribute_group_a" : { "attribute_a" : "" ,"attribute_b" : "" ,"attribute_c" : "" ,"attribute_d" : "" }, ,"attribute_group_b" : { "attribute_subgroup_b_a" : { "attribute_a" : "" ,"attribute_b" : "" ,"attribute_c" : "" ,"attribute_d" : "" } ,"attribute_subgroup_b_b" : { "attribute_a" : "" ,"attribute_b" : "" ,"attribute_c" : "" ,"attribute_d" : "" } } } 

所以可以说我想更新att_subgrp_b_a:

 exports.updateProfil = function(req, res, item, callback) { var email = req.session.email; db.collection('profiles', function(err, collection) { collection.update({"email": email},{$set: item}, function(err, result) 

var“item”看起来像:

 { attribute_group_b: { attribute_subgroupgroup_b_a: { att_a: "xy" ,att_b: "xy" } } } 

当我现在更新文件=>它删除attr_group_b中的所有内容,并将其replace为“item”

这意味着attr_subgrp_b_b已经完全消失,并且没有更新(attr_subgrp_b_a)的所有其他属性

我希望它在“项目”中查找属性,将它们replace为数据库,让所有其他obj不变

尝试下面的查询

  var email='emailid'; var item='whichuwanttoupdate'; collection.update( {"email": email}, {$set:{'attribute_group_b.attribute_subgroup_b_a':item}}, function(err,result){ });