Searching and retrieving multiple documents at once

2,385 views
Skip to first unread message

Sachin Anand

unread,
Dec 15, 2011, 4:10:45 AM12/15/11
to mongod...@googlegroups.com
Hi All,

Is there a way I can retrieve multiple documents in a single query which have different ids.

I want to retrieve document with ids as "_id":"sachin", "_id":"Doug", "_id":"Michael" in a single query.

The sql query would be something like :

select * from table_name where _id in ("sachin", "Doug", "Michael")

Thanks.
--
With Regards

Sachin Anand

Nat

unread,
Dec 15, 2011, 4:15:12 AM12/15/11
to mongod...@googlegroups.com
Use $in operator.

db.persons.find({_id:{$in: ["sachin", "Doug", "Michael"]}});

Sachin Anand

unread,
Dec 15, 2011, 4:16:54 AM12/15/11
to mongod...@googlegroups.com
I am looking for the java api usage. Any pointers.

Shekhar Vemuri

unread,
Dec 15, 2011, 4:17:25 AM12/15/11
to mongod...@googlegroups.com, mongod...@googlegroups.com
--
You received this message because you are subscribed to the Google Groups "mongodb-user" group.
To post to this group, send email to mongod...@googlegroups.com.
To unsubscribe from this group, send email to mongodb-user...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/mongodb-user?hl=en.

Sachin Anand

unread,
Dec 15, 2011, 4:17:53 AM12/15/11
to mongod...@googlegroups.com
Thanks Nat, 

I am looking for its java api usage. Guess I was late with my update.

--
You received this message because you are subscribed to the Google Groups "mongodb-user" group.
To view this discussion on the web visit https://groups.google.com/d/msg/mongodb-user/-/McoIzc0aEjoJ.

To post to this group, send email to mongod...@googlegroups.com.
To unsubscribe from this group, send email to mongodb-user...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/mongodb-user?hl=en.

Sachin Anand

unread,
Dec 15, 2011, 4:21:08 AM12/15/11
to mongod...@googlegroups.com
Thanks Nat and Shekhar. I guess this would work : new BasicDBObject(['_id':['$in':['e','b']]])
Reply all
Reply to author
Forward
0 new messages