'How can I return the document with only the searched array?
I try to update a document, but it contains an array of objects. Here's the model:
const User = new Schema({
lastName: String,
firstName: String,
accounts: [{
status: Number,
nickName: String
}
]
})
So first I found the ID of the object in the array and I updated it:
User.findOneAndUpdate({
"accounts._id": req.body.ID,
"accounts.status": 1
}, {
$set: {
"accounts.$.status": 0
}
})
But if my documents have more of one object in the accounts array, it returns me all of them... There's an option to get just the array that I updated?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
