How would I select the subdocument author, in the below shown object, without directly accessing it, ie authors[0]
, so that the result that I get back is {"_id":"4f44af6a024342300e000002", visible: true}
?
The object:
{
_id: "4f44af6a024342300e000001",
title: "A book",
created: "2012-02-22T14:12:51.305Z"
authors: [{"_id":"4f44af6a024342300e000002", visible: true}]
}
I have been able to update it by doing this, but selecting it seems like a completely different story:
books.update({_id: "4f44af6a024342300e000001",'authors._id': "4f44af6a024342300e000002"},
{$set: {'books.$.visible': true}}, function(err) {
// ...
});