我有这四个文件:
{
"_id" : "qbz2nyPccFzYjYmWo",
"position" : 0,
"part_order" : 30
},
{
"_id" : "qbz2nyPccFzYjYmWo",
"position" : 1,
"part_order" : 34
},
{
"_id" : "EaCSGEKmqfrgFFXBs",
"position" : 2
},
{
"_id" : "N3Z6NnWhN35dX4MLq",
"position" : 3,
"part_order" : 31
}
我想订购这个系列。我尝试过:
db.queue.find().sort({part_order:1,position:1})
但它将文件与没有part_order的part_order分开。 如何在位置修复文档,只需在mongo查询中使用part_order对文档进行排序?
输出必须是:
{
"_id" : "qbz2nyPccFzYjYmWo",
"position" : 0,
"part_order" : 30
},
{
"_id" : "N3Z6NnWhN35dX4MLq",
"position" : 3,
"part_order" : 31
},
{
"_id" : "EaCSGEKmqfrgFFXBs",
"position" : 2
},
{
"_id" : "qbz2nyPccFzYjYmWo",
"position" : 1,
"part_order" : 34
}