完整地说,这是您实际尝试执行的操作:
pipe := DB.C("store").Pipe([]bson.M{ {"$project": bson.M{"location": bson.M{"type": bson.M{"$literal": "Point"}, "coordinates": []interface{}{"$longitude", "$latitude"}}}}, {"$match": bson.M{"location": bson.M{"$geoWithin": bson.M{"$centerSphere": []interface{}{"$coordinates", 10 / 6378.11}}}}},})问题不在于您的
"Point"字面意义,仅是巧合。
"Pt"例如,如果将其更改为,您仍然会看到完全相同的错误消息。
该
Point错误消息是指
$centerSphere,这需要一个中心
点 和半径。而且您尝试“通过”的方式不起作用。
例如,这适用于:
"$centerSphere": []interface{}{[]interface{}{1.0, 2.0}, 10 / 6378.11}原始查询没有意义,因为您尝试查找位置在距 其自身 10公里之内的文档,该文档将匹配所有文档。
相反,您希望/应该查询距 特定 位置10公里以内的文档,并且可以将此特定位置的坐标传递给
$centerSphere:
myLong, myLat := 10.0, 20.0// ..."$centerSphere": []interface{}{[]interface{}{myLong, myLat}, 10 / 6378.11}完整的查询:
myLong, myLat := 10.0, 20.0pipe := DB.C("store").Pipe([]bson.M{ {"$project": bson.M{"location": bson.M{"type": bson.M{"$literal": "Point"}, "coordinates": []interface{}{"$longitude", "$latitude"}}}}, {"$match": bson.M{"location.coordinates": bson.M{"$geoWithin": bson.M{"$centerSphere": []interface{}{[]interface{}{myLong, myLat}, 10 / 6378.11}}}}},})


