I have these four documents:
{
"_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
}
I want to order the collection. I tried with:
db.queue.find().sort({part_order:1,position:1})
But it separates the documents with part_order of without part_order. How Can I fix documents in the positions and just order the documents with part_order in a mongo query?
The output has to be:
{
"_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
}