0

How could I do the following in mongo?

db.questions.find( { _id: { $in: [ "506b422ff42c95000e000004", "506b422ff42c95000e00007a", "506b422ff42c95000e00008d"] } } ).sort( {_id: { $in: [ "506b422ff42c95000e00007a", "506b422ff42c95000e00008d", "506b422ff42c95000e000004"]}});

Is it even possible or do I have to do this on the code end?

Kamilski81
  • 14,409
  • 33
  • 108
  • 161

1 Answers1

1

No, not really. You'll need to do that yourself. The results won't come back in the order you construct your query. See this similar question: Order of responses to MongoDB $in query?

Your ID's do look numerically ordered though and they're based on date, so you could sort on _id itself, but there's no way of even determining if those objects would even be stored in that order in the database.

Community
  • 1
  • 1
cirrus
  • 5,624
  • 8
  • 44
  • 62