相关疑难解决方法(0)

如何在数组字段中对子文档进行排序?

我正在使用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"
    }]
}
Run Code Online (Sandbox Code Playgroud)

我想得到的是,相同的结构,但订购 "topics" : []

{
"_id" : "32022",
"topics" : [
    {
        "weight" : 305.70093587160807,
        "words" : "WORDZ"
    },
    {
        "weight" : 289.8354232846977,
        "words" : "wowz even more wordz"
    },
    {
        "weight" …
Run Code Online (Sandbox Code Playgroud)

mongodb pymongo mongodb-query aggregation-framework

2
推荐指数
1
解决办法
3572
查看次数