我是Mongodb和Mongoose的新手。我有用户收藏。因此我必须根据电子邮件的用户ID插入或更新。
我使用了以下查询
var query={"userid":req.body.user_id,
"email":req.body.email,
"firstname":req.body.first_name,
"lastname":req.body.last_name,
"mobilenumber":req.body.phone_number};
db.update(query, {$set: {userid: req.body.user_id }}, {upsert:true},
function(err,doc){
if(err) {
response = {"MethodName":"RegisterUser","isFault" : true,"ResponseData" : "Error adding data"};
}
else {
response = {"MethodName":"RegisterUser","isFault" : false,"ResponseData" : "User Registration completed successfully"};
}
}); // Added this here. Check your code if it is missing.
但这会引发无效的回调参数错误。
当我删除{upsert:true}
时,我没有收到任何错误。但是数据没有更新。当我添加{upsert:true}
时,我收到以下错误,
我得到的错误。
Error: Invalid callback() argument.
at Query.update (/var/www/html/chymnee/node_modules/mongoose/lib/query.js:2062:13)
at Function.update (/var/www/html/chymnee/node_modules/mongoose/lib/model.js:1986:13)
at model.update (/var/www/html/chymnee/node_modules/mongoose/lib/document.js:429:34)
at /var/www/html/chymnee/server.js:39:13
at Layer.handle [as handle_request] (/var/www/html/chymnee/node_modules/express/lib/router/layer.js:95:5)
at next (/var/www/html/chymnee/node_modules/express/lib/router/route.js:131:13)
at Route.dispatch (/var/www/html/chymnee/node_modules/express/lib/router/route.js:112:3)
at Layer.handle [as handle_request] (/var/www/html/chymnee/node_modules/express/lib/router/layer.js:95:5)
at /var/www/html/chymnee/node_modules/express/lib/router/index.js:277:22
at Function.process_params (/var/www/html/chymnee/node_modules/express/lib/router/index.js:330:12)
at next (/var/www/html/chymnee/node_modules/express/lib/router/index.js:271:10)
at Function.handle (/var/www/html/chymnee/node_modules/express/lib/router/index.js:176:3)
at router (/var/www/html/chymnee/node_modules/express/lib/router/index.js:46:12)
at Layer.handle [as handle_request] (/var/www/html/chymnee/node_modules/express/lib/router/layer.js:95:5)
at trim_prefix (/var/www/html/chymnee/node_modules/express/lib/router/index.js:312:13)
at /var/www/html/chymnee/node_modules/express/lib/router/index.js:280:7
请帮忙。