db.collection('community')
.aggregate()
.geoNear({
distanceField: 'distance', // 输出的每个记录中 distance 即是与给定点的距离
spherical: true,
near: db.Geo.Point(113.3089506, 23.0968251),
key: 'tlocation', // 若只有 location 一个地理位置索引的字段,则不需填
includeLocs: 'tlocation', // 若只有 location 一个是地理位置,则不需填
})
.end()
报错信息:
Error: FailedOperation, (BadValue) error processing query: ns=tnt-8s0waqgok.community limit=100Tree: GEONEAR field=tlocation maxdist=1.79769e+308 isNearSphere=1
Sort: {}
Proj: { $pt: { $meta: "geoNearPoint" }, $dis: { $meta: "geoNearDistance" } }
Collation: { locale: "simple" }
planner returned error: unable to find index for $geoNear query (7288dde9-86a8-4cbd-a766-31bce4c37275)
已添加将tlocation添加为索引
community表结构如下
填了和填对,是两码事