Node.js Mongoose findOneAndUpdate——更新对象数组中的对象
看看这个模式:Node.js Mongoose findOneAndUpdate——更新对象数组中的对象,node.js,mongodb,mongoose,mongoose-schema,Node.js,Mongodb,Mongoose,Mongoose Schema,看看这个模式: let userSchema = new Schema({ email: { type: String, required: true }, password: { type: String, required: true }, books: [{ cover: String, title: String, link: String, requests: { requestingUser: String, bookOffered: String,
let userSchema = new Schema({
email: { type: String, required: true },
password: { type: String, required: true },
books: [{
cover: String,
title: String,
link: String,
requests: { requestingUser: String, bookOffered: String,
beingRequested: false }
}],
ip: String
});
我试图做的是使用findOneAndUpdate
来(基于给定的信息)找到正确的用户,然后(从给定标题的书籍数组中)找到正确的书籍,并更新请求字段(这是另一个对象)。这是否可以仅通过一个findOneAndUpdate
查询来完成
到目前为止,我的发现是,我必须执行findOne
以获得正确的用户,然后执行嵌套在其中的findOneAndUpdate
。有没有一种方法可以通过一个查询命令来实现这一点
谢谢类似于
findOneAndUpdate({“email”:emailvalue,“books.title”:titlevalue},{“books.requests.requestingUser”:uservalue},…
是的,它现在工作了,不知道为什么以前不工作。可能是