MongoDB
 SQL >> Database >  >> NoSQL >> MongoDB

Costruire query GeoNear in MongoDB con C#

Per usare GeoNear in C# devi prima creare un indice geospaziale e poi configurare le opzioni.

var earthRadius = 6378.0;
var rangeInKm = 3000.0;

myCollection.EnsureIndex(IndexKeys.GeoSpatial("Location"));

var near = Query.GT("ExpiresOn", now);
var options = GeoNearOptions
  .SetMaxDistance(rangeInKm / earthRadius)
  .SetSpherical(true);

var results = myCollection.GeoNear(
  near,
  request.Longitude,
  request.Latitude,
  200,
  options
);