0
我蒙戈集合包含諸如下列文件:蒙戈套疊的鍵排序
{
"_id" : ObjectId("52de74863fcc41ddfc7b23a5"),
"ts" : "1385969614848",
"Info" : [
{
"out" : 0,
"Type" : "1",
"Descr" : "Null0",
},
{
"out" : 10,
"Type" : "1",
"Descr" : "Null",
},
{
"out" : 20000,
"Type" : "1",
"Descr" : "Null0",
},
{
"out" : 70,
"Type" : "10",
"Descr" : "abc",
}
]
}
{
"_id" : ObjectId("52de74863fcc41ddfc7b23a6"),
"ts" : "1385969614852",
"Info" : [
{
"out" : 500,
"Type" : "1",
"Descr" : "Null0",
},
{
"out" : 100,
"Type" : "1",
"Descr" : "Null",
},
{
"out" : 2896,
"Type" : "1",
"Descr" : "Null0",
},
{
"out" : 4052,
"Type" : "10",
"Descr" : "abc",
}
]
}
我要排序的關鍵「走出去」。爲了做到這一點,我寫了下面蒙戈查詢:
db.collection_name.find({},{"Info.out":1}).sort({"Info.out":1}).pretty()
話,就說明下面的輸出:
{
"_id" : ObjectId("52fa2922d73ddc832323f402"),
"Info" : [
{
"out" : 0
},
{
"out" : 10
},
{
"out" : 20000
},
{
"out" : 70
}
]
}
{
"_id" : ObjectId("52fa292ed73ddc832323f403"),
"Info" : [
{
"out" : 500
},
{
"out" : 100
},
{
"out" : 2896
},
{
"out" : 4052
}
]
}
但是,我希望下面的輸出:
{
"_id" : ObjectId("52fa2922d73ddc832323f402"),
"Info" : [
{
"out" : 20000
},
{
"out" : 70
},
{
"out" : 10
},
{
"out" : 0
}
]
}
{
"_id" : ObjectId("52fa292ed73ddc832323f403"),
"Info" : [
{
"out" : 4052
},
{
"out" : 2896
},
{
"out" : 500
},
{
"out" : 100
}
]
}
有誰知道如何達到預期的輸出?
它工作正常:) – Yogesh
很高興幫助!請接受答案:) – Jinxcat
我做了一個mongotry可視化輸出:http://mongotry.herokuapp.com/#?bookmarkId=52fb8dc14e86f9020071ed73 – bla