我想从查询查询更新返回的文档,但即使我没有使用下面的代码出现任何错误,它也无法正常工作:
var projectId = req.params.projectId
var object = req.body
var updatedProject = sanitizeProjectObject(object)
Project.findOne({project_id: projectId}, function(err, project) {
if(err)
next(err)
if(!project)
next(new Error(404, "Couldn't find a project with this id"))
if(!isAllowedToEditProject(req, project))
next(new Error(403, "You are not allowed to edit this project"))
project.update({ $set: updatedProject }, function(err, resultProject) {
logger.info(resultProject)
})
})
输出是:
3:32:07 AM - info:ok = 0,n = 0,nModified = 0
updatedProject对象包含已更改的文档的8个字段中的5个。我可以确认“updatedProject”中这些字段的值与存储的值不同。
那么如何使用mongoose从数据库更新返回的文档?