0

我正在尝试对 mongodb 集合使用 mongoose 地理空间查询。“2dsphere”索引已应用于位置对象。

询问

请在下面找到查询:

const data = await Banks.find(
    {
        location: {
            $near: {
                $geometry: {
                    type: "Point",
                    coordinates: [73.8567, 18.5204]
                },
                $maxDistance: 10000000
            }
        }
    }
);

console.log('-- the data --', data);

数据

许多文档之一如下所示:

{
    "_id" : ObjectId("5c64511a04ede20c28f6ef0b"),
    "location" : {
        "coordinates" : [ 
            92.747338, 
            11.675442
        ],
        "type" : "Point"
    },
    "name" : "Test name",
}

我试过的

我试图将最大距离设置得尽可能大。但是查询不会检索任何文档。可能是什么问题呢?

4

1 回答 1

0

上面提到的查询工作正常。我指的是错误的模型名称(集合)。集合名称是银行,我一直指的是银行。模型名称在 MongoDB 中区分大小写。

于 2019-02-21T16:23:56.427 回答