Mongo按组查询前N个

时间:2019-07-18 11:18:25

标签: mongodb

以下是我在收藏中的mongo文件。

在这里,paths.live是一个字符串。

(结束生存)将给出pathId的距离。 如果实时值为N / A,则可以忽略PathId。 应该将所有旅行者的位置距离加在一起,并按距离排在前10位。

{
    "_id" : ObjectId("5d304870bc975c1c48a2ce66"),
    "locationName" : "boston",
    "travellers" : [
        {
            "travellerName" : "Mike",
            "paths" : [
                {
                    "pathId" : 0,
                    "start" : NumberLong(10),
                    "end" : NumberLong(100),
                    "live" : "N/A"
                },
                {
                    "pathId" : 1,
                    "start" : NumberLong(10),
                    "end" : NumberLong(101),
                    "live" : "50"
                }
            ]
        },
        {
            "travellerName" : "Peter",
            "paths" : [
                {
                    "pathId" : 0,
                    "start" : NumberLong(0),
                    "end" : NumberLong(200),
                    "live" : "140"
                },
                {
                    "pathId" : 1,
                    "start" : NumberLong(10),
                    "end" : NumberLong(101),
                    "live" : "50"
                }
            ]
        }
    ]
},
{
    "_id" : ObjectId("5d304870bc975c1c48a2ce66"),
    "locationName" : "chicaco",
    "travellers" : [
        {
            "travellerName" : "William",
            "paths" : [
                {
                    "pathId" : 0,
                    "start" : NumberLong(101),
                    "end" : NumberLong(250),
                    "live" : "200"
                },
                {
                    "pathId" : 1,
                    "start" : NumberLong(10),
                    "end" : NumberLong(101),
                    "live" : "50"
                }
            ]
        },
        {
            "travellerName" : "Kane",
            "paths" : [
                {
                    "pathId" : 0,
                    "start" : NumberLong(0),
                    "end" : NumberLong(200),
                    "live" : "140"
                },
                {
                    "pathId" : 1,
                    "start" : NumberLong(10),
                    "end" : NumberLong(101),
                    "live" : "60"
                }
            ]
        }
    ]
}

0 个答案:

没有答案