【发布时间】:2019-09-10 16:15:40
【问题描述】:
我正在处理地理位置查询,我想获得满足地理位置查询的集合总数。 Mongo go 库提供 Document Count 方法,不支持基于地理位置的过滤器。
我得到的错误是: (BadValue) 在此上下文中不允许使用 $geoNear、$near 和 $nearSphere
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)
【问题讨论】:
-
查询是什么?
-
该错误很有帮助,但您需要在问题中包含相关代码。
-
我已经添加了示例代码。