问题
Take a look at this 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,
beingRequested: false }
}],
ip: String
});
What I am trying to do is use findOneAndUpdate
to (based on given information) find the correct user, and then find the correct book (from the array of books by given title) And update the requests field (which is another object.) Is this possible to accomplish with only one findOneAndUpdate
query ?
So far my finding has been that I would have to do a findOne
to get the correct user, and then do a findOneAndUpdate
nested inside that. Is there a way to do this with one query command?
Thanks
来源:https://stackoverflow.com/questions/43128561/mongoose-findoneandupdate-updating-an-object-inside-an-array-of-objects