I have some data that looks like this:
{
"_id" : "5227aa5d9881d31cd3aa0e78",
"Message" : "This is a message 5:47 PM",
"IssuedAt" : ISODate("2013-09-04T21:47:09.932Z"),
"Users" : [
{
"_id" : "dhBHuZL9M+hqtKIx14iu",
"IsRead" : true
},
{
"_id" : "SOMSOMOMODJFJDFKJKDJF",
"IsRead" : false
}
]
}
and I was hoping retrieve the following about one user:
{
"_id" : "5227aa5d9881d31cd3aa0e78",
"Message" : "This is a message 5:47 PM",
"IssuedAt" : ISODate("2013-09-04T21:47:09.932Z"),
"IsRead" : false
}
I tried this but it will only return the record with the whole subdocument:
db.collection.find({"Users": {$elemMatch: {"_id": 'dhBHuZL9M+hqtKIx14iu'}}}, {"Message": 1, "Users.$.IsRead": 1}).pretty()
Is there a way to get what I am looking for without using aggregate?