Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Learn more about Collectives

Teams

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Learn more about Teams

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.

A single document isn't possible at this point and I'm already going with option B. Thanks. Soviut May 19, 2010 at 18:51 I just had this problem too, and I think map/reduce may be an option too. mongodb.org/display/DOCS/MapReduce sandstrom Sep 16, 2010 at 19:42

I use a Python driver, so forgive my not-so-mongodb syntax:

users = list(db.Users.find({'Age':30}))
posts = list(db.Posts.find({'User':{'$in':users}}))
client = MongoClient('ip', 27017)
client.the_database.authenticate('user', 'password', source='db_name')
db = client['db_name']
user = db['user']
user_id = user.find_one({'email': '[email protected]'}).get('_id')
client_user_relation = db['client_user_relation']
print(client_user_relation.find_one())
print(user_id)
print(DBRef(collection = "user", id = user_id))
print(client_user_relation.find_one({'user': DBRef(collection = "user", id = user_id)}))
        

Thanks for contributing an answer to Stack Overflow!

  • Please be sure to answer the question. Provide details and share your research!

But avoid

  • Asking for help, clarification, or responding to other answers.
  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.