Re: embeded document multipul condition?

12 views
Skip to first unread message

Stephen Steneker

unread,
Oct 5, 2012, 9:16:36 AM10/5/12
to mongod...@googlegroups.com
//The results are as follows: I want to

{
"UserId" : "ace002",
"TargetUsers" : [
 {"TargetUserId" : "bce005","MultipulUsers" : [ { "MultipulUserId" : "cce005" } ] }
]
}

How do I get the same results as above?

 Hi,

I think you are looking for the new $elemMatch projection in MongoDB 2.2, which limits output to the first matching element of an array:

  db.collections.find({  "UserId":"ace002"}, { _id: 0, UserId:1, "TargetUsers": { $elemMatch: {TargetUserId: "bce005"} }} )


Your original syntax was using $elemMatch in the query rather than the projection .. 

Cheers,
Stephen
Reply all
Reply to author
Forward
0 new messages