Mongo subquery embedded docs

in mongo db I have the following: db.users:

{ username: "me", 
companies: {
 meco:
     {groups:
       ['addr1','addr2','addr3']
     }
 ,
 youco:
     {groups:
       ['addr1','addr4']
     }
},
 someco:
     {groups:
       ['addr8','addr9']
     }
}

}

I'm trying to find all users that have (company=meco & group has 'addr1') OR (company=youco & group has addr4). How would I do this? thx,

John,

Firstly, please be aware the "someco" document is not nested within companies.

That aside the basic syntax you are after is "{"$or" : [{"companies.meco.groups" : "addr1"}, {"companies.youco.groups" : "addr4"}]}

Please have a look at the Dotted Notation Docs: http://www.mongodb.org/display/DOCS/Dot+Notation+(Reaching+into+Objects)

And the Advanced Queries $or Docs http://www.mongodb.org/display/DOCS/Advanced+Queries#AdvancedQueries-%24or

Cheers,

David