【发布时间】:2018-07-10 18:34:06
【问题描述】:
考虑以下猫鼬查询:
mongoose.model(collection).findOneAndUpdate({[fieldName]: fieldValue}, {$set:{processed:1}}, {new:true}, function(err, doc){
console.log(doc);
callback(err, doc);
});
这将返回具有属性 processed:1 的文档,但它不会更新 mongodb 表。
我没有在猫鼬模式上设置已处理的属性。所以架构会是这样的:
var mongoose = require('mongoose');
module.exports = mongoose.model('collection', {
_id:mongoose.Schema.Types.ObjectId,
parm1:{type: String},
parm2:{type: Number},
parm3:{type: String, index:true}
}, 'mycollection');
我是否可以设置任何选项,使其在更新数据库记录的同时返回更新后的文档?
【问题讨论】:
标签: node.js mongodb mongoose mongoose-schema