Can some expert point the best ways to a Geospacial search using official C# driver in MongoDB. Best Object constructor(strings /doubles), Build an index, find near. Many thanks for your help.
db.places.ensureIndex( { loc : "2d" } , { min : -500 , max : 500 } ),
db.places.find( { loc : { $near : [50,50] , $maxDistance : 5 } } ).limit(20),
The C# equivalent to those Mongo shell commands is:
places.EnsureIndex(IndexKeys.GeoSpatial("loc"), IndexOptions.SetGeoSpatialRange(-500, 500));
var query = Query.Near("loc", 50, 50, 5);
var cursor = places.Find(query).SetLimit(20);
foreach (var hit in cursor) {
// process hit
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With