首页 > 解决方案 > Pymongo $geoWithin 查询不返回任何文档

问题描述

我正在使用 $geoWithin 运算符查询 MongoDB 集合,但没有收到任何文档作为响应。

这是我数据库中的示例文档:

{
    "_id": {
        "$oid": "608a2296594b7e54c0067426"
    },
    "properties": {
        "id": "MONR365005",
        "unit": "Unit 2",
        "number": "94",
        "street": "Crittenden Way",
        "city": "Brighton",
        "district": "Monroe",
        "region": "NY",
        "postcode": "14623",
        "hash": "3d8b0721e06b6ad8",
        "Realtor_ID": 0
    },
    "location": {
        "type": "Point",
        "coordinates": [43.1016143, -77.6340374]
    }
}

这是我要执行的查询:

nearest = self.geoCoords.aggregate([{"$match": {"location": {
            "$geoWithin": {"$centerSphere": [[start[0], start[1]], self.distance_radians(self.feet_meter(radius))]}}}}])
print(list(nearest))

如何解决此问题以使查询返回正确数量的文档?非常感谢!

标签: pythonpymongo

解决方案


推荐阅读