I have a user model with the following schema
{
_id: userId,
inbox: {
inbox: [Array of message documents],
sent: [Array of message documents],
}
}
Is there a way to get only the updated subdocument after an update in mongodb / mongoose ?
The update is good i just want to return the updated subdocument instead of querying the db again
db.getCollection("users").findOneAndUpdate(
{ "inbox.sent._id": ObjectId("5cea23be8c03c800d43a8376") },
{ "$set": { "inbox.sent.$.inTrash": false } },
{ "inbox.sent.$": 1 } <-- how to return only the subdocument like in a query
);
expected output the array at inbox.sent with only the updated doc
{
_id: userId,
inbox: {
sent: [{ updated doc}]
}
}