Node.js 如何在猫鼬';s findOneAndUpdate筛选器?
通过在过滤器中设置Node.js 如何在猫鼬';s findOneAndUpdate筛选器?,node.js,mongodb,mongoose,Node.js,Mongodb,Mongoose,通过在过滤器中设置\u id,我发现无法使用findOneAndUpdate之后。答案是我必须在模式中定义它。如果我把_id放在模式中,我得到 Error [MongooseError]: document must have an _id before saving 我同意。应该由Mongo来设置Id 那么如何在findOneAndUpdate中使用_id 更新: var orderSchema = new mongoose.Schema({ deleted: Boolean,
\u id
,我发现无法使用findOneAndUpdate
之后。答案是我必须在模式中定义它。如果我把_id放在模式中,我得到
Error [MongooseError]: document must have an _id before saving
我同意。应该由Mongo来设置Id
那么如何在findOneAndUpdate
中使用_id
更新:
var orderSchema = new mongoose.Schema({
deleted: Boolean,
client: {
name: String,
phone: String
},
products: [{
name: String,
quantity: Number,
price: Number
}],
seller_id: Number,
order_id: Number,
total: Number
});
我想用
let r = await Order.findOneAndUpdate({ _id: idExample, seller_id: json.seller_id }, order);
但是,它抱怨没有
\u id
和idExample
。中的答案告诉我在模式中使用\u id:String
,但随后我得到错误[MongooseError]:文档在保存之前必须有一个_id您能给我们使用findOneAndUpdate
的代码吗?失败,请在DB中添加请求/实际文档。@srinivasy我更新了。你能看一看吗?这个订单给你带来了什么。findOne({u id:idExample,seller\u id:json.seller\u id})
-你能把文档设置为null
?当然你不需要在模式中指定\u id
字段,尤其是当它的字符串
时,我想你的问题是更新部分的订单
,是什么?你能给我们使用findOneAndUpdate
的代码吗?失败,请在DB中添加请求/实际文档..@srinivasy i updated。你能看一看吗?这个订单给你带来了什么。findOne({u id:idExample,seller\u id:json.seller\u id})
-你能把文档设置为null
?当然你不需要在模式中指定\u id
字段,尤其是当它的字符串
时,我想你的问题是更新部分的顺序,是什么?