tags:

views:

53

answers:

1

Whats the best way to access/query a DB Ref: UPDATE:

users: name, groupref : {$ref:"groups",$id:"ObjectId ..." } }
groups: name, topic, country,...,..

Assumption is that user belongs to only one group, how would I get all users for a group whose country starts with the letter 'A'? Country is a string.

Also, how would it change if users belonegd to more than 1 group.

A: 

Assuming "user" is in the collection "users" and "group" is in the collection "groups":

db.users.find({groupref : {$ref : "groups", $id : group._id}})
kristina