I\'ve looked through the mongoose API, and many questions on SO and on the google group, and still can\'t figure out updating embedded documents.
I\'m trying to upda
when you already have the user, you can just do something like this:
var listing = req.user.userListings.id(req.params.listingId);
listing.isRead = args.isRead;
listing.isFavorite = args.isFavorite;
listing.isArchived = args.isArchived;
req.user.save(function (err) {
// ...
});
as found here: http://mongoosejs.com/docs/subdocs.html
Finding a sub-document
Each document has an _id. DocumentArrays have a special id method for looking up a document by its _id.
var doc = parent.children.id(id);
* * warning * *
as @zach pointed out, you have to declare the sub-document's schema before the actual document 's schema to be able to use the id()
method.