0

I'm using the $in operator in a query in this way.

{ customer_id: "55681864527cb123208b4567", 
_id: { $in: [ 
"56cf29693f2c755a0a8b459f", "56cde0213f2c756b0a8b4569", "56cddfbc3f2c75580a8b4567"
] }

These are the results.

{ "_id" : ObjectId("56cddfbc3f2c75580a8b4567"), "customer_id" : "55681864527cb123208b4567", "id" : "56cddfbc3f2c75580a8b4567"}
{ "_id" : ObjectId("56cde0213f2c756b0a8b4569"), "customer_id" : "55681864527cb123208b4567", "id" : "56cde0213f2c756b0a8b4569"}
{ "_id" : ObjectId("56cf29693f2c755a0a8b459f"), "customer_id" : "55681864527cb123208b4567", "id" : "56cf29693f2c755a0a8b459f"}

The results order don't respect my search order and that make sense.

I need that the results order begin with the id 56cf29693f2c755a0a8b459f and end with the id 56cddfbc3f2c75580a8b4567. Respecting my search order.

{ "_id" : ObjectId("56cf29693f2c755a0a8b459f"), "customer_id" : "55681864527cb123208b4567", "id" : "56cf29693f2c755a0a8b459f"}
{ "_id" : ObjectId("56cde0213f2c756b0a8b4569"), "customer_id" : "55681864527cb123208b4567", "id" : "56cde0213f2c756b0a8b4569"}
{ "_id" : ObjectId("56cddfbc3f2c75580a8b4567"), "customer_id" : "55681864527cb123208b4567", "id" : "56cddfbc3f2c75580a8b4567"}

But, there is any way to achieve that?.

Thanks.

icalvete
  • 987
  • 2
  • 16
  • 50
  • JohnnyHK, you are right. This question already has an answer. Should I delete this one? What is the convention? Thanks in any case. – icalvete Feb 25 '16 at 17:17
  • It's up to you. The system will delete it after 30 days if your duplicate question isn't deemed useful. See [here](http://meta.stackoverflow.com/questions/252955/what-do-i-do-if-my-question-happens-to-be-a-duplicate) for some guidance. – JohnnyHK Feb 25 '16 at 18:38

0 Answers0