I am working on geo location query where I want to get total number of collections that satisfy geo location query. Mongo go library provides Document Count method with doesn't support filter based on geo location.
The error I am getting is: (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)