MongoDB
 sql >> Base de Dados >  >> NoSQL >> MongoDB

Construção de consulta MongoDb C# GeoNear

Encontrei a resposta através disto e disto:

var earthRadius = 6378.0; // km
var rangeInKm = 3000.0; // km

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

var near =
    Query.GT("ExpiresOn", now);

var options = GeoNearOptions
    .SetMaxDistance(rangeInKm / earthRadius /* to radians */)
    .SetSpherical(true);

var results = myCollection.GeoNear(
    near,
    request.Longitude, // note the order
    request.Latitude,  // [lng, lat]
    200,
    options
);