我以这种方式在查询中使用$ in运算符。
{ customer_id: "55681864527cb123208b4567",
_id: { $in: [
"56cf29693f2c755a0a8b459f", "56cde0213f2c756b0a8b4569", "56cddfbc3f2c75580a8b4567"
] }
这些是结果。
{ "_id" : ObjectId("56cddfbc3f2c75580a8b4567"), "customer_id" : "55681864527cb123208b4567", "id" : "56cddfbc3f2c75580a8b4567"}
{ "_id" : ObjectId("56cde0213f2c756b0a8b4569"), "customer_id" : "55681864527cb123208b4567", "id" : "56cde0213f2c756b0a8b4569"}
{ "_id" : ObjectId("56cf29693f2c755a0a8b459f"), "customer_id" : "55681864527cb123208b4567", "id" : "56cf29693f2c755a0a8b459f"}
结果顺序不符合我的搜索顺序,这是有道理的。
我需要结果顺序以id 56cf29693f2c755a0a8b459f 开头,并以id 56cddfbc3f2c75580a8b4567 结束。尊重我的搜索顺序。
{ "_id" : ObjectId("56cf29693f2c755a0a8b459f"), "customer_id" : "55681864527cb123208b4567", "id" : "56cf29693f2c755a0a8b459f"}
{ "_id" : ObjectId("56cde0213f2c756b0a8b4569"), "customer_id" : "55681864527cb123208b4567", "id" : "56cde0213f2c756b0a8b4569"}
{ "_id" : ObjectId("56cddfbc3f2c75580a8b4567"), "customer_id" : "55681864527cb123208b4567", "id" : "56cddfbc3f2c75580a8b4567"}
但是,有什么办法可以实现这一目标吗?
感谢。