Answer the question
In order to leave comments, you need to log in
How in MongoDB (mgo) to display the nearest documents with the distance to it?
If I get without distance like this:
err = c.Find(bson.M{
"location": bson.M{
"$nearSphere": bson.M{
"$geometry": bson.M{
"type": "Point",
"coordinates": []float64{lat, long},
},
"$maxDistance": scope,
},
},
}).All(&places)
Answer the question
In order to leave comments, you need to log in
$geoNear aggregator can do this
err = c.Pipe(bson.M{
"$geoNear": bson.M{
"spherical": "true",
"distanceField": "distance",
"near": bson.M{
"type": "Point",
"coordinates": []float64{lat, long},
},
"maxDistance": scope,
},
}).All(&places)
distance
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question