【发布时间】:2017-05-07 15:53:41
【问题描述】:
使用save函数通过post方法插入数据,在同样的方法中需要得到与我们插入的带有id的文档相同的json数据
apiRoutes.post('/doctor', function(req, res){
if(!req.body.Name || !req.body.password){
res.json({success: false, msg: 'please pass the username and password'});
}else{
var newUser = new Doctor({
Name:req.body.Name,
password : req.body.password,
});
newUser.save(function(err){
if(err){
res.json({success: false, msg :'username alredy existes'});
}else{
res.json({success: true, msg : 'Successfull created user'});
}
});
}
});
res.json中需要返回与文档网的_id相同的文档名和密码
【问题讨论】:
-
你也在用 express 吗?
-
是的,我正在使用 Express @se
标签: javascript json node.js mongodb mongoose