@@ -604,7 +604,7 @@ public static PipelineStageDefinition<TInput, TOutput> Facet<TInput, TOutput>(
604
604
{
605
605
return Facet < TInput , TOutput > ( ( IEnumerable < AggregateFacet < TInput > > ) facets ) ;
606
606
}
607
-
607
+
608
608
/// <summary>
609
609
/// Creates a $geoNear stage.
610
610
/// </summary>
@@ -616,7 +616,8 @@ public static PipelineStageDefinition<TInput, TOutput> Facet<TInput, TOutput>(
616
616
/// <returns>The stage.</returns>
617
617
internal static PipelineStageDefinition < TInput , TOutput > GeoNear < TInput , TPoint , TOutput > (
618
618
TPoint near ,
619
- GeoNearOptions < TInput > options = null )
619
+ GeoNearOptions < TInput , TOutput > options = null )
620
+ // where TPoint is either a GeoJsonPoint or a legacy coordinate array
620
621
{
621
622
const string operatorName = "$geoNear" ;
622
623
var stage = new DelegatedPipelineStageDefinition < TInput , TOutput > (
@@ -625,26 +626,27 @@ internal static PipelineStageDefinition<TInput, TOutput> GeoNear<TInput, TPoint,
625
626
{
626
627
ClientSideProjectionHelper . ThrowIfClientSideProjection ( args . DocumentSerializer , operatorName ) ;
627
628
var pointSerializer = args . SerializerRegistry . GetSerializer < TPoint > ( ) ;
629
+ var outputSerializer = options ? . OutputSerializer ?? args . GetSerializer < TOutput > ( ) ;
630
+ var outputRenderArgs = args . WithNewDocumentType ( outputSerializer ) ;
628
631
var geoNearOptions = new BsonDocument
629
632
{
630
633
{ "near" , pointSerializer . ToBsonValue ( near ) } ,
631
- { "distanceField" , options ? . DistanceField , options ? . DistanceField != null } ,
632
- { "maxDistance" , ( ) => options ? . MaxDistance . Value , options ? . MaxDistance != null } ,
633
- { "minDistance" , ( ) => options ? . MinDistance . Value , options ? . MinDistance != null } ,
634
- { "distanceMultiplier" , ( ) => options ? . DistanceMultiplier . Value , options ? . DistanceMultiplier != null } ,
634
+ { "distanceField" , options ? . DistanceField ? . Render ( outputRenderArgs ) . FieldName , options ? . DistanceField != null } ,
635
+ { "maxDistance" , options ? . MaxDistance , options ? . MaxDistance != null } ,
636
+ { "minDistance" , options ? . MinDistance , options ? . MinDistance != null } ,
637
+ { "distanceMultiplier" , options ? . DistanceMultiplier , options ? . DistanceMultiplier != null } ,
635
638
{ "key" , options ? . Key , options ? . Key != null } ,
636
639
{ "query" , options ? . Query ? . Render ( args ) , options ? . Query != null } ,
637
- { "includeLocs" , options ? . IncludeLocs , options ? . IncludeLocs != null } ,
638
- { "spherical" , ( ) => options ? . Spherical . Value , options ? . Spherical != null }
640
+ { "includeLocs" , options ? . IncludeLocs ? . Render ( outputRenderArgs ) . FieldName , options ? . IncludeLocs != null } ,
641
+ { "spherical" , options ? . Spherical , options ? . Spherical != null }
639
642
} ;
640
-
641
- var outputSerializer = args . SerializerRegistry . GetSerializer < TOutput > ( ) ;
643
+
642
644
return new RenderedPipelineStageDefinition < TOutput > ( operatorName , new BsonDocument ( operatorName , geoNearOptions ) , outputSerializer ) ;
643
645
} ) ;
644
-
646
+
645
647
return stage ;
646
648
}
647
-
649
+
648
650
/// <summary>
649
651
/// Creates a $geoNear stage.
650
652
/// </summary>
@@ -656,31 +658,13 @@ internal static PipelineStageDefinition<TInput, TOutput> GeoNear<TInput, TPoint,
656
658
/// <returns>The stage.</returns>
657
659
public static PipelineStageDefinition < TInput , TOutput > GeoNear < TInput , TCoordinates , TOutput > (
658
660
GeoJsonPoint < TCoordinates > near ,
659
- GeoNearOptions < TInput > options = null )
661
+ GeoNearOptions < TInput , TOutput > options = null )
660
662
where TCoordinates : GeoJsonCoordinates
661
663
{
662
664
Ensure . IsNotNull ( near , nameof ( near ) ) ;
663
665
return GeoNear < TInput , GeoJsonPoint < TCoordinates > , TOutput > ( near , options ) ;
664
666
}
665
-
666
- /// <summary>
667
- /// Creates a $geoNear stage.
668
- /// </summary>
669
- /// <typeparam name="TInput">The type of the input documents.</typeparam>
670
- /// <typeparam name="TOutput">The type of the output documents.</typeparam>
671
- /// <typeparam name="TCoordinates">The type of the coordinates for the point.</typeparam>
672
- /// <param name="near">The point for which to find the closest documents.</param>
673
- /// <param name="options">The options.</param>
674
- /// <returns>The stage.</returns>
675
- public static PipelineStageDefinition < TInput , TOutput > GeoNear < TInput , TCoordinates , TOutput > (
676
- TCoordinates [ ] near ,
677
- GeoNearOptions < TInput > options = null )
678
- {
679
- Ensure . IsNotNull ( near , nameof ( near ) ) ;
680
- Ensure . That ( near . Length , len => len is >= 2 and <= 3 , nameof ( near ) , "Legacy coordinates array should have 2 or 3 coordinates." ) ;
681
- return GeoNear < TInput , TCoordinates [ ] , TOutput > ( near , options ) ;
682
- }
683
-
667
+
684
668
/// <summary>
685
669
/// Creates a $geoNear stage.
686
670
/// </summary>
@@ -690,12 +674,12 @@ public static PipelineStageDefinition<TInput, TOutput> GeoNear<TInput, TCoordina
690
674
/// <param name="options">The options.</param>
691
675
/// <returns>The stage.</returns>
692
676
public static PipelineStageDefinition < TInput , TOutput > GeoNear < TInput , TOutput > (
693
- BsonDocument near ,
694
- GeoNearOptions < TInput > options = null )
677
+ double [ ] near ,
678
+ GeoNearOptions < TInput , TOutput > options = null )
695
679
{
696
680
Ensure . IsNotNull ( near , nameof ( near ) ) ;
697
- Ensure . That ( near . ElementCount , len => len is >= 2 and <= 3 , nameof ( near ) , "Legacy coordinates document should have 2 or 3 coordinates." ) ;
698
- return GeoNear < TInput , BsonDocument , TOutput > ( near , options ) ;
681
+ Ensure . That ( near . Length , len => len is >= 2 and <= 3 , nameof ( near ) , "Legacy coordinates array should have 2 or 3 coordinates." ) ;
682
+ return GeoNear < TInput , double [ ] , TOutput > ( near , options ) ;
699
683
}
700
684
701
685
/// <summary>
0 commit comments