Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/sockets/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
更新Mongodb集合对象。Node.JS MongoDB_Node.js_Mongodb - Fatal编程技术网

更新Mongodb集合对象。Node.JS MongoDB

更新Mongodb集合对象。Node.JS MongoDB,node.js,mongodb,Node.js,Mongodb,在数据库中创建记录的函数的一部分: exports.postForm = function(req,res){ var User = db.model("User", dbUser); var newUser = new User({ id: "todo", role: "inactive", sessionid : "todo", activeKey : authKey, salt: "t

在数据库中创建记录的函数的一部分:

exports.postForm = function(req,res){
    var User = db.model("User", dbUser);
    var newUser = new User({
         id: "todo",
         role: "inactive",
         sessionid : "todo",
         activeKey : authKey,
         salt: "todo",
         password  : req.body.password,
         profile: {
               name      : req.body.firstname,
               surname   : req.body.surname, 
               username  : req.body.displayname, 
               email     : email,
               twitter   : "todo",
               facebook  : "todo",
         }
    newUser.save(function(err, newData){....}
现在,如果现有用户更改了个人信息,则需要在数据库中进行更改。 例如,需要更改
配置文件
对象中的
用户名
。 如何在不更改系统字段(如
sessionID
role
)的情况下更新
profile


非常感谢

您可以使用

save
将简单地替换文档的所有内容<代码>更新仅允许您更新已更改的零件