我的数据库结构看起来像:
{
"_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“项目”看起来像:
{
attribute_group_b:
{
attribute_subgroupgroup_b_a:
{
att_a: "xy"
,att_b: "xy"
}
}
}
当我现在更新文件时 => 它会删除 attr_group_b 中的所有内容并将其替换为“item”
这意味着 attr_subgrp_b_b 完全消失了,所有其他属性(attr_subgrp_b_a)都没有更新
我希望它在“项目”中查找属性,将它们替换到数据库中,让所有其他 obj 保持不变