@@ -511,45 +511,51 @@ public void TestNearWithGeoJson()
511
511
[ Test ]
512
512
public void TestNearWithGeoJsonWithMaxDistance ( )
513
513
{
514
- var point = GeoJson . Point ( GeoJson . Geographic ( 40 , 18 ) ) ;
515
- var query = Query . Near ( "loc" , point , 42 ) ;
516
- var expected = "{ 'loc' : { '$near' : { '$geometry' : { 'type' : 'Point', 'coordinates' : [40.0, 18.0] }, '$maxDistance' : 42.0 } } }" . Replace ( "'" , "\" " ) ;
517
- Assert . AreEqual ( expected , query . ToJson ( ) ) ;
518
-
519
- var collection = Configuration . TestCollection ;
520
- collection . Drop ( ) ;
521
- collection . CreateIndex ( IndexKeys . GeoSpatialSpherical ( "loc" ) ) ;
522
- collection . Insert ( new BsonDocument { { "_id" , 1 } , { "loc" , GeoJson . Point ( GeoJson . Geographic ( 1 , 1 ) ) . ToBsonDocument ( ) } } ) ;
523
- collection . Insert ( new BsonDocument { { "_id" , 2 } , { "loc" , GeoJson . Point ( GeoJson . Geographic ( 2 , 2 ) ) . ToBsonDocument ( ) } } ) ;
524
-
525
- var circumferenceOfTheEarth = 40075000 ; // meters at the equator, approx
526
- var metersPerDegree = circumferenceOfTheEarth / 360.0 ;
527
- query = Query . Near ( "loc" , GeoJson . Point ( GeoJson . Geographic ( 0 , 0 ) ) , 2.0 * metersPerDegree ) ;
528
- var results = collection . Find ( query ) . ToList ( ) ;
529
- Assert . AreEqual ( 1 , results . Count ) ;
530
- Assert . AreEqual ( 1 , results [ 0 ] [ "_id" ] . ToInt32 ( ) ) ;
514
+ if ( _primary . Supports ( FeatureId . GeoJson ) )
515
+ {
516
+ var point = GeoJson . Point ( GeoJson . Geographic ( 40 , 18 ) ) ;
517
+ var query = Query . Near ( "loc" , point , 42 ) ;
518
+ var expected = "{ 'loc' : { '$near' : { '$geometry' : { 'type' : 'Point', 'coordinates' : [40.0, 18.0] }, '$maxDistance' : 42.0 } } }" . Replace ( "'" , "\" " ) ;
519
+ Assert . AreEqual ( expected , query . ToJson ( ) ) ;
520
+
521
+ var collection = Configuration . TestCollection ;
522
+ collection . Drop ( ) ;
523
+ collection . CreateIndex ( IndexKeys . GeoSpatialSpherical ( "loc" ) ) ;
524
+ collection . Insert ( new BsonDocument { { "_id" , 1 } , { "loc" , GeoJson . Point ( GeoJson . Geographic ( 1 , 1 ) ) . ToBsonDocument ( ) } } ) ;
525
+ collection . Insert ( new BsonDocument { { "_id" , 2 } , { "loc" , GeoJson . Point ( GeoJson . Geographic ( 2 , 2 ) ) . ToBsonDocument ( ) } } ) ;
526
+
527
+ var circumferenceOfTheEarth = 40075000 ; // meters at the equator, approx
528
+ var metersPerDegree = circumferenceOfTheEarth / 360.0 ;
529
+ query = Query . Near ( "loc" , GeoJson . Point ( GeoJson . Geographic ( 0 , 0 ) ) , 2.0 * metersPerDegree ) ;
530
+ var results = collection . Find ( query ) . ToList ( ) ;
531
+ Assert . AreEqual ( 1 , results . Count ) ;
532
+ Assert . AreEqual ( 1 , results [ 0 ] [ "_id" ] . ToInt32 ( ) ) ;
533
+ }
531
534
}
532
535
533
536
[ Test ]
534
537
public void TestNearWithGeoJsonWithSpherical ( )
535
538
{
536
- var point = GeoJson . Point ( GeoJson . Geographic ( 40 , 18 ) ) ;
537
- var query = Query . Near ( "loc" , point , 42 , true ) ;
538
- var expected = "{ 'loc' : { '$nearSphere' : { '$geometry' : { 'type' : 'Point', 'coordinates' : [40.0, 18.0] }, '$maxDistance' : 42.0 } } }" . Replace ( "'" , "\" " ) ;
539
- Assert . AreEqual ( expected , query . ToJson ( ) ) ;
540
-
541
- var collection = Configuration . TestCollection ;
542
- collection . Drop ( ) ;
543
- collection . CreateIndex ( IndexKeys . GeoSpatialSpherical ( "loc" ) ) ;
544
- collection . Insert ( new BsonDocument { { "_id" , 1 } , { "loc" , GeoJson . Point ( GeoJson . Geographic ( 1 , 1 ) ) . ToBsonDocument ( ) } } ) ;
545
- collection . Insert ( new BsonDocument { { "_id" , 2 } , { "loc" , GeoJson . Point ( GeoJson . Geographic ( 2 , 2 ) ) . ToBsonDocument ( ) } } ) ;
546
-
547
- var circumferenceOfTheEarth = 40075000 ; // meters at the equator, approx
548
- var metersPerDegree = circumferenceOfTheEarth / 360.0 ;
549
- query = Query . Near ( "loc" , GeoJson . Point ( GeoJson . Geographic ( 0 , 0 ) ) , 2.0 * metersPerDegree , true ) ;
550
- var results = collection . Find ( query ) . ToList ( ) ;
551
- Assert . AreEqual ( 1 , results . Count ) ;
552
- Assert . AreEqual ( 1 , results [ 0 ] [ "_id" ] . ToInt32 ( ) ) ;
539
+ if ( _primary . Supports ( FeatureId . GeoJson ) )
540
+ {
541
+ var point = GeoJson . Point ( GeoJson . Geographic ( 40 , 18 ) ) ;
542
+ var query = Query . Near ( "loc" , point , 42 , true ) ;
543
+ var expected = "{ 'loc' : { '$nearSphere' : { '$geometry' : { 'type' : 'Point', 'coordinates' : [40.0, 18.0] }, '$maxDistance' : 42.0 } } }" . Replace ( "'" , "\" " ) ;
544
+ Assert . AreEqual ( expected , query . ToJson ( ) ) ;
545
+
546
+ var collection = Configuration . TestCollection ;
547
+ collection . Drop ( ) ;
548
+ collection . CreateIndex ( IndexKeys . GeoSpatialSpherical ( "loc" ) ) ;
549
+ collection . Insert ( new BsonDocument { { "_id" , 1 } , { "loc" , GeoJson . Point ( GeoJson . Geographic ( 1 , 1 ) ) . ToBsonDocument ( ) } } ) ;
550
+ collection . Insert ( new BsonDocument { { "_id" , 2 } , { "loc" , GeoJson . Point ( GeoJson . Geographic ( 2 , 2 ) ) . ToBsonDocument ( ) } } ) ;
551
+
552
+ var circumferenceOfTheEarth = 40075000 ; // meters at the equator, approx
553
+ var metersPerDegree = circumferenceOfTheEarth / 360.0 ;
554
+ query = Query . Near ( "loc" , GeoJson . Point ( GeoJson . Geographic ( 0 , 0 ) ) , 2.0 * metersPerDegree , true ) ;
555
+ var results = collection . Find ( query ) . ToList ( ) ;
556
+ Assert . AreEqual ( 1 , results . Count ) ;
557
+ Assert . AreEqual ( 1 , results [ 0 ] [ "_id" ] . ToInt32 ( ) ) ;
558
+ }
553
559
}
554
560
555
561
[ Test ]
0 commit comments