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){ });
- 等待从Node + Expressredirect的挂起types
- Node.js-Ejs-Mongojs堆栈上的“没有方法”forEach“TypeError”
- 表示节点-http-proxy,proxy.proxyRequest到https服务器?
- 在Node.JS中parsingMicrosoft Office文件
- 在运行nodejs + expressjs时访问aws-lambda上下文
- Angular $ http POST从ExpressJS中获得null
- Node Js + MySql + Express – app.use(bodyParser()); 没有定义 – 错误build立连接到新的SQL方法
- PassportJs的passport.session()与file upload冲突 – 不会写入文件
- Nodejs – Req.body未定义在后快速4.9.0