我正在使用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检查更新的问题 –