views:

325

answers:

1

Is it possible to query through a DBRef using a single find spec?

user collection

{
    'age': 30
}

post collection

{
    'user': DBRef('user', ...)
}

Is it possible to query for all post who's users are 30 in a single find step? If not, would it be wise to create a javascript function to handle the multi-stage operation or will that cause blocking problems?

+2  A: 

it's not possible to do that. i would recommend either:

a) changing your data model so that all of the data is in a single document (might not be possible depending on your case).

b) querying for users who are 30 first, and then doing a second query to get posts where user is $in that list. i would do this client side rather than using server-side JS or anything like that.

mdirolf
A single document isn't possible at this point and I'm already going with option B. Thanks.
Soviut
I just had this problem too, and I think map/reduce may be an option too. http://www.mongodb.org/display/DOCS/MapReduce
sandstrom