我正在研究地理位置查询,我想获得满足地理位置查询的集合总数。Mongo go 库提供 Document Count 方法,不支持基于地理位置的过滤器。
我得到的错误是: (BadValue) $geoNear, $near, and $nearSphere are not allowed in this context
filter := bson.D{
{
Key: "address.location",
Value: bson.D{
{
Key: "$nearSphere",
Value: bson.D{
{
Key: "$geometry",
Value: bson.D{
{
Key: "type",
Value: "Point",
},
{
Key: "coordinates",
Value: bson.A{query.Longitude, query.Latitude},
},
},
},
{
Key: "$maxDistance",
Value: maxDistance,
},
},
},
},
},
}
collection := db.Database("catalog").Collection("restaurant")
totalCount, findError := collection.CountDocuments(ctx, filter)