我正在使用MongoDB shell獲取一些結果,並進行了排序。這裏有一個採樣器,如何對數組字段中的子文檔進行排序?
{
"_id" : "32022",
"topics" : [
{
"weight" : 281.58551703724993,
"words" : "some words"
},
{
"weight" : 286.6695125796183,
"words" : "some more words"
},
{
"weight" : 289.8354232846977,
"words" : "wowz even more wordz"
},
{
"weight" : 305.70093587160807,
"words" : "WORDZ"
}]
}
我要得到什麼,同樣的結構,而是由"topics" : []
{
"_id" : "32022",
"topics" : [
{
"weight" : 305.70093587160807,
"words" : "WORDZ"
},
{
"weight" : 289.8354232846977,
"words" : "wowz even more wordz"
},
{
"weight" : 286.6695125796183,
"words" : "some more words"
},
{
"weight" : 281.58551703724993,
"words" : "some words"
},
]
}
我設法弄到一些有序的結果排序,但在由id字段分組他們沒有運氣。有沒有辦法做到這一點?
您需要向我們展示了與樣本文件預期的結果,而不僅僅是你得到的結果。 – styvane
@ user3100115檢查更新的問題 –