MongoDB - 地理空间距离问题

fde*_*ose 0 geolocation mongodb

我在属性"location"上有一个2d地理空间索引.我正在尝试查询纬度/经度位置的给定范围内的某些实体.如果我使用geoNear命令,我得到正确的结果:

distances = db.runCommand({ geoNear: "Places", near: [40.423776,-3.711534], spherical: true, maxDistance: 10/6378}).results
Run Code Online (Sandbox Code Playgroud)

输出给定坐标10公里范围内的所有位置.

但如果我执行以下查询,我得不到任何结果: db.Places.find({location: { $near [40.423776,-3.711534], $maxDistance: 10/6378, $nearSphere: true }})

难道我做错了什么?

Ram*_*Vel 5

应该像这样使用$ nearSphere

db.Places.find({location:{$nearSphere:[[40.423776,-3.711534],10/6378]}}).count()
Run Code Online (Sandbox Code Playgroud)

希望能帮助到你