0

Here is my query statement.

db.users.find({"_id":{"$in":[id0, id1, id2]}})

Of course it will return correct user array, but the sequence is random, it could be

[user1, user0, user2]

or

[user2, user0, user1]

it depends on ids' value.

If there is a way that I could force mongodb always return user array like this

db.users.find({"_id":{"$in":[id0, id1, id2]}}) => [user0, user1, user2]
db.users.find({"_id":{"$in":[id1, id0, id2]}}) => [user1, user0, user2]
tinyproxy
  • 385
  • 1
  • 3
  • 15
  • possible duplicate of [Order of responses to MongoDB $in query?](http://stackoverflow.com/questions/3142260/order-of-responses-to-mongodb-in-query) – Will Shaver Dec 05 '14 at 04:00

1 Answers1

0

I don't know if the query syntax supports that (I wouldn't think so), but you can always post-process the results to hash them by lookup id

Andras
  • 2,995
  • 11
  • 17
  • That's how I handle query result now. Because I am not familiar with mongodb, so I wonder if there is a cool way to do it. – tinyproxy Dec 05 '14 at 03:38