/// <summary> /// Start a fluent aggregation pipeline with a $GeoNear stage with the supplied parameters /// </summary> /// <param name="NearCoordinates">The coordinates from which to find documents from</param> /// <param name="DistanceField">x => x.Distance</param> /// <param name="Spherical">Calculate distances using spherical geometry or not</param> /// <param name="MaxDistance">The maximum distance in meters from the center point that the documents can be</param> /// <param name="MinDistance">The minimum distance in meters from the center point that the documents can be</param> /// <param name="Limit">The maximum number of documents to return</param> /// <param name="Query">Limits the results to the documents that match the query</param> /// <param name="DistanceMultiplier">The factor to multiply all distances returned by the query</param> /// <param name="IncludeLocations">Specify the output field to store the point used to calculate the distance</param> /// <param name="IndexKey"></param> /// <param name="options">The options for the aggregation. This is not required.</param> /// <typeparam name="T">The type of entity</typeparam> /// <param name="ignoreGlobalFilters">Set to true if you'd like to ignore any global filters for this operation</param> public IAggregateFluent <T> GeoNear <T>(Coordinates2D NearCoordinates, Expression <Func <T, object> > DistanceField, bool Spherical = true, int?MaxDistance = null, int?MinDistance = null, int?Limit = null, BsonDocument Query = null, int?DistanceMultiplier = null, Expression <Func <T, object> > IncludeLocations = null, string IndexKey = null, AggregateOptions options = null, bool ignoreGlobalFilters = false) where T : IEntity { var globalFilter = Logic.MergeWithGlobalFilter(ignoreGlobalFilters, globalFilters, Builders <T> .Filter.Empty); if (globalFilter != Builders <T> .Filter.Empty) { return(DB .FluentGeoNear(NearCoordinates, DistanceField, Spherical, MaxDistance, MinDistance, Limit, Query, DistanceMultiplier, IncludeLocations, IndexKey, options, Session) .Match(globalFilter)); } return(DB.FluentGeoNear(NearCoordinates, DistanceField, Spherical, MaxDistance, MinDistance, Limit, Query, DistanceMultiplier, IncludeLocations, IndexKey, options, Session)); }
/// <summary> /// Start a fluent aggregation pipeline with a $GeoNear stage with the supplied parameters. /// </summary> /// <param name="NearCoordinates">The coordinates from which to find documents from</param> /// <param name="DistanceField">x => x.Distance</param> /// <param name="Spherical">Calculate distances using spherical geometry or not</param> /// <param name="MaxDistance">The maximum distance in meters from the center point that the documents can be</param> /// <param name="MinDistance">The minimum distance in meters from the center point that the documents can be</param> /// <param name="Limit">The maximum number of documents to return</param> /// <param name="Query">Limits the results to the documents that match the query</param> /// <param name="DistanceMultiplier">The factor to multiply all distances returned by the query</param> /// <param name="IncludeLocations">Specify the output field to store the point used to calculate the distance</param> /// <param name="IndexKey"></param> /// <param name="options">The options for the aggregation. This is not required.</param> /// <param name="session">An optional session if using within a transaction</param> public static IAggregateFluent <T> FluentGeoNear <T>(Coordinates2D NearCoordinates, Expression <Func <T, object> > DistanceField, bool Spherical = true, double?MaxDistance = null, double?MinDistance = null, int?Limit = null, BsonDocument Query = null, double?DistanceMultiplier = null, Expression <Func <T, object> > IncludeLocations = null, string IndexKey = null, AggregateOptions options = null, IClientSessionHandle session = null, string db = null) where T : IEntity { return((new GeoNear <T> { near = NearCoordinates, distanceField = DistanceField?.FullPath(), spherical = Spherical, maxDistance = MaxDistance, minDistance = MinDistance, query = Query, distanceMultiplier = DistanceMultiplier, limit = Limit, includeLocs = IncludeLocations?.FullPath(), key = IndexKey, }) .ToFluent(options, session, db)); }
/// <summary> /// Start a fluent aggregation pipeline with a $GeoNear stage with the supplied parameters. /// </summary> /// <param name="NearCoordinates">The coordinates from which to find documents from</param> /// <param name="DistanceField">x => x.Distance</param> /// <param name="Spherical">Calculate distances using spherical geometry or not</param> /// <param name="MaxDistance">The maximum distance from the center point that the documents can be</param> /// <param name="MinDistance">The minimum distance from the center point that the documents can be</param> /// <param name="Limit">The maximum number of documents to return</param> /// <param name="Query">Limits the results to the documents that match the query</param> /// <param name="DistanceMultiplier">The factor to multiply all distances returned by the query</param> /// <param name="IncludeLocations">Specify the output field to store the point used to calculate the distance</param> /// <param name="IndexKey"></param> /// <param name="options">The options for the aggregation. This is not required.</param> /// <param name="session">An optional session if using within a transaction</param> public IAggregateFluent <T> FluentGeoNear <T>(Coordinates2D NearCoordinates, Expression <Func <T, object> > DistanceField, bool Spherical = true, double?MaxDistance = null, double?MinDistance = null, int?Limit = null, BsonDocument Query = null, double?DistanceMultiplier = null, Expression <Func <T, object> > IncludeLocations = null, string IndexKey = null, AggregateOptions options = null, IClientSessionHandle session = null) where T : IEntity { return(FluentGeoNear(NearCoordinates, DistanceField, Spherical, MaxDistance, MinDistance, Limit, Query, DistanceMultiplier, IncludeLocations, IndexKey, options, session, DbName)); }
/// <summary> /// Specify criteria for matching entities based on GeoSpatial data (longitude & latitude) /// <para>TIP: Make sure to define a Geo2DSphere index with DB.Index<T>() before searching</para> /// <para>Note: DB.FluentGeoNear() supports more advanced options</para> /// </summary> /// <param name="coordinatesProperty">The property where 2DCoordinates are stored</param> /// <param name="nearCoordinates">The search point</param> /// <param name="maxDistance">Maximum distance in meters from the search point</param> /// <param name="minDistance">Minimum distance in meters from the search point</param> public Distinct <T, TProperty> Match(Expression <Func <T, object> > coordinatesProperty, Coordinates2D nearCoordinates, double?maxDistance = null, double?minDistance = null) { return(Match(f => f.Near(coordinatesProperty, nearCoordinates.ToGeoJsonPoint(), maxDistance, minDistance))); }