多个2dsphere索引,不确定在哪个上运行geoNear

时间:2019-10-28 17:44:26

标签: node.js mongodb

我收到“多个2dsphere索引,不能确定要在其上运行geoNear”的错误,我使用键符号指定了哪个字段,但仍然出现错误,我被卡住了!

这是我的mongodb中的文档结构

{
    "_id": {
        "$oid": ".."
    },
    "name": "Donna",
        .
        .
        .

    "cor": {
        "type": "Point",
        "coordinates": [
            -79.3935716,
            43.6872606
        ]
    }
}
pipeline=[
                   {
                     $geoNear: {
                        near: { type: "Point", 
                                                 coordinates: [43.653225 ,-79.383186] },
                        key: "cor",
                        distanceField: "distance",
                        query: filter
                     }
                   },
                   { $sort: { "distance": 1} },
                   { $limit: 10}
                ]

db.collection(THERAPISTS_COLLECTION).createIndex({cor: "2dsphere"});
db.collection(THERAPISTS_COLLECTION).aggregate(pipeline).toArray(function (err, therapists) {

)};

0 个答案:

没有答案