@@ -652,53 +652,67 @@ private class Place
652
652
[ Test ]
653
653
public void TestGeoHaystackSearch ( )
654
654
{
655
- if ( _collection . Exists ( ) ) { _collection . Drop ( ) ; }
656
- _collection . Insert ( new Place { Location = new [ ] { 34.2 , 33.3 } , Type = "restaurant" } ) ;
657
- _collection . Insert ( new Place { Location = new [ ] { 34.2 , 37.3 } , Type = "restaurant" } ) ;
658
- _collection . Insert ( new Place { Location = new [ ] { 59.1 , 87.2 } , Type = "office" } ) ;
659
- _collection . CreateIndex ( IndexKeys . GeoSpatialHaystack ( "Location" , "Type" ) , IndexOptions . SetBucketSize ( 1 ) ) ;
660
-
661
- var options = GeoHaystackSearchOptions
662
- . SetLimit ( 30 )
663
- . SetMaxDistance ( 6 )
664
- . SetQuery ( "Type" , "restaurant" ) ;
665
- var result = _collection . GeoHaystackSearchAs < Place > ( 33 , 33 , options ) ;
666
- Assert . IsTrue ( result . Ok ) ;
667
- Assert . IsTrue ( result . Stats . Duration >= TimeSpan . Zero ) ;
668
- Assert . AreEqual ( 2 , result . Stats . BTreeMatches ) ;
669
- Assert . AreEqual ( 2 , result . Stats . NumberOfHits ) ;
670
- Assert . AreEqual ( 34.2 , result . Hits [ 0 ] . Document . Location [ 0 ] ) ;
671
- Assert . AreEqual ( 33.3 , result . Hits [ 0 ] . Document . Location [ 1 ] ) ;
672
- Assert . AreEqual ( "restaurant" , result . Hits [ 0 ] . Document . Type ) ;
673
- Assert . AreEqual ( 34.2 , result . Hits [ 1 ] . Document . Location [ 0 ] ) ;
674
- Assert . AreEqual ( 37.3 , result . Hits [ 1 ] . Document . Location [ 1 ] ) ;
675
- Assert . AreEqual ( "restaurant" , result . Hits [ 1 ] . Document . Type ) ;
655
+ using ( _database . RequestStart ( ) )
656
+ {
657
+ var instance = _server . RequestConnection . ServerInstance ;
658
+ if ( instance . InstanceType != MongoServerInstanceType . ShardRouter )
659
+ {
660
+ if ( _collection . Exists ( ) ) { _collection . Drop ( ) ; }
661
+ _collection . Insert ( new Place { Location = new [ ] { 34.2 , 33.3 } , Type = "restaurant" } ) ;
662
+ _collection . Insert ( new Place { Location = new [ ] { 34.2 , 37.3 } , Type = "restaurant" } ) ;
663
+ _collection . Insert ( new Place { Location = new [ ] { 59.1 , 87.2 } , Type = "office" } ) ;
664
+ _collection . CreateIndex ( IndexKeys . GeoSpatialHaystack ( "Location" , "Type" ) , IndexOptions . SetBucketSize ( 1 ) ) ;
665
+
666
+ var options = GeoHaystackSearchOptions
667
+ . SetLimit ( 30 )
668
+ . SetMaxDistance ( 6 )
669
+ . SetQuery ( "Type" , "restaurant" ) ;
670
+ var result = _collection . GeoHaystackSearchAs < Place > ( 33 , 33 , options ) ;
671
+ Assert . IsTrue ( result . Ok ) ;
672
+ Assert . IsTrue ( result . Stats . Duration >= TimeSpan . Zero ) ;
673
+ Assert . AreEqual ( 2 , result . Stats . BTreeMatches ) ;
674
+ Assert . AreEqual ( 2 , result . Stats . NumberOfHits ) ;
675
+ Assert . AreEqual ( 34.2 , result . Hits [ 0 ] . Document . Location [ 0 ] ) ;
676
+ Assert . AreEqual ( 33.3 , result . Hits [ 0 ] . Document . Location [ 1 ] ) ;
677
+ Assert . AreEqual ( "restaurant" , result . Hits [ 0 ] . Document . Type ) ;
678
+ Assert . AreEqual ( 34.2 , result . Hits [ 1 ] . Document . Location [ 0 ] ) ;
679
+ Assert . AreEqual ( 37.3 , result . Hits [ 1 ] . Document . Location [ 1 ] ) ;
680
+ Assert . AreEqual ( "restaurant" , result . Hits [ 1 ] . Document . Type ) ;
681
+ }
682
+ }
676
683
}
677
684
678
685
[ Test ]
679
686
public void TestGeoHaystackSearch_Typed ( )
680
687
{
681
- if ( _collection . Exists ( ) ) { _collection . Drop ( ) ; }
682
- _collection . Insert ( new Place { Location = new [ ] { 34.2 , 33.3 } , Type = "restaurant" } ) ;
683
- _collection . Insert ( new Place { Location = new [ ] { 34.2 , 37.3 } , Type = "restaurant" } ) ;
684
- _collection . Insert ( new Place { Location = new [ ] { 59.1 , 87.2 } , Type = "office" } ) ;
685
- _collection . CreateIndex ( IndexKeys < Place > . GeoSpatialHaystack ( x => x . Location , x => x . Type ) , IndexOptions . SetBucketSize ( 1 ) ) ;
686
-
687
- var options = GeoHaystackSearchOptions < Place >
688
- . SetLimit ( 30 )
689
- . SetMaxDistance ( 6 )
690
- . SetQuery ( x => x . Type , "restaurant" ) ;
691
- var result = _collection . GeoHaystackSearchAs < Place > ( 33 , 33 , options ) ;
692
- Assert . IsTrue ( result . Ok ) ;
693
- Assert . IsTrue ( result . Stats . Duration >= TimeSpan . Zero ) ;
694
- Assert . AreEqual ( 2 , result . Stats . BTreeMatches ) ;
695
- Assert . AreEqual ( 2 , result . Stats . NumberOfHits ) ;
696
- Assert . AreEqual ( 34.2 , result . Hits [ 0 ] . Document . Location [ 0 ] ) ;
697
- Assert . AreEqual ( 33.3 , result . Hits [ 0 ] . Document . Location [ 1 ] ) ;
698
- Assert . AreEqual ( "restaurant" , result . Hits [ 0 ] . Document . Type ) ;
699
- Assert . AreEqual ( 34.2 , result . Hits [ 1 ] . Document . Location [ 0 ] ) ;
700
- Assert . AreEqual ( 37.3 , result . Hits [ 1 ] . Document . Location [ 1 ] ) ;
701
- Assert . AreEqual ( "restaurant" , result . Hits [ 1 ] . Document . Type ) ;
688
+ using ( _database . RequestStart ( ) )
689
+ {
690
+ var instance = _server . RequestConnection . ServerInstance ;
691
+ if ( instance . InstanceType != MongoServerInstanceType . ShardRouter )
692
+ {
693
+ if ( _collection . Exists ( ) ) { _collection . Drop ( ) ; }
694
+ _collection . Insert ( new Place { Location = new [ ] { 34.2 , 33.3 } , Type = "restaurant" } ) ;
695
+ _collection . Insert ( new Place { Location = new [ ] { 34.2 , 37.3 } , Type = "restaurant" } ) ;
696
+ _collection . Insert ( new Place { Location = new [ ] { 59.1 , 87.2 } , Type = "office" } ) ;
697
+ _collection . CreateIndex ( IndexKeys < Place > . GeoSpatialHaystack ( x => x . Location , x => x . Type ) , IndexOptions . SetBucketSize ( 1 ) ) ;
698
+
699
+ var options = GeoHaystackSearchOptions < Place >
700
+ . SetLimit ( 30 )
701
+ . SetMaxDistance ( 6 )
702
+ . SetQuery ( x => x . Type , "restaurant" ) ;
703
+ var result = _collection . GeoHaystackSearchAs < Place > ( 33 , 33 , options ) ;
704
+ Assert . IsTrue ( result . Ok ) ;
705
+ Assert . IsTrue ( result . Stats . Duration >= TimeSpan . Zero ) ;
706
+ Assert . AreEqual ( 2 , result . Stats . BTreeMatches ) ;
707
+ Assert . AreEqual ( 2 , result . Stats . NumberOfHits ) ;
708
+ Assert . AreEqual ( 34.2 , result . Hits [ 0 ] . Document . Location [ 0 ] ) ;
709
+ Assert . AreEqual ( 33.3 , result . Hits [ 0 ] . Document . Location [ 1 ] ) ;
710
+ Assert . AreEqual ( "restaurant" , result . Hits [ 0 ] . Document . Type ) ;
711
+ Assert . AreEqual ( 34.2 , result . Hits [ 1 ] . Document . Location [ 0 ] ) ;
712
+ Assert . AreEqual ( 37.3 , result . Hits [ 1 ] . Document . Location [ 1 ] ) ;
713
+ Assert . AreEqual ( "restaurant" , result . Hits [ 1 ] . Document . Type ) ;
714
+ }
715
+ }
702
716
}
703
717
704
718
[ Test ]
@@ -1262,21 +1276,28 @@ public void TestMapReduceInlineWithQuery()
1262
1276
[ Test ]
1263
1277
public void TestReIndex ( )
1264
1278
{
1265
- _collection . RemoveAll ( ) ;
1266
- _collection . Insert ( new BsonDocument ( "x" , 1 ) ) ;
1267
- _collection . Insert ( new BsonDocument ( "x" , 2 ) ) ;
1268
- _collection . DropAllIndexes ( ) ;
1269
- _collection . CreateIndex ( "x" ) ;
1270
- // note: prior to 1.8.1 the reIndex command was returning duplicate ok elements
1271
- try
1279
+ using ( _database . RequestStart ( ) )
1272
1280
{
1273
- var result = _collection . ReIndex ( ) ;
1274
- Assert . AreEqual ( 2 , result . Response [ "nIndexes" ] . ToInt32 ( ) ) ;
1275
- Assert . AreEqual ( 2 , result . Response [ "nIndexesWas" ] . ToInt32 ( ) ) ;
1276
- }
1277
- catch ( InvalidOperationException ex )
1278
- {
1279
- Assert . AreEqual ( "Duplicate element name 'ok'." , ex . Message ) ;
1281
+ var instance = _server . RequestConnection . ServerInstance ;
1282
+ if ( instance . InstanceType != MongoServerInstanceType . ShardRouter )
1283
+ {
1284
+ _collection . RemoveAll ( ) ;
1285
+ _collection . Insert ( new BsonDocument ( "x" , 1 ) ) ;
1286
+ _collection . Insert ( new BsonDocument ( "x" , 2 ) ) ;
1287
+ _collection . DropAllIndexes ( ) ;
1288
+ _collection . CreateIndex ( "x" ) ;
1289
+ // note: prior to 1.8.1 the reIndex command was returning duplicate ok elements
1290
+ try
1291
+ {
1292
+ var result = _collection . ReIndex ( ) ;
1293
+ Assert . AreEqual ( 2 , result . Response [ "nIndexes" ] . ToInt32 ( ) ) ;
1294
+ Assert . AreEqual ( 2 , result . Response [ "nIndexesWas" ] . ToInt32 ( ) ) ;
1295
+ }
1296
+ catch ( InvalidOperationException ex )
1297
+ {
1298
+ Assert . AreEqual ( "Duplicate element name 'ok'." , ex . Message ) ;
1299
+ }
1300
+ }
1280
1301
}
1281
1302
}
1282
1303
@@ -1409,34 +1430,41 @@ public void TestUpdateNullQuery()
1409
1430
[ Test ]
1410
1431
public void TestValidate ( )
1411
1432
{
1412
- // ensure collection exists
1413
- _collection . RemoveAll ( ) ;
1414
- _collection . Insert ( new BsonDocument ( "x" , 1 ) ) ;
1415
-
1416
- var result = _collection . Validate ( ) ;
1417
- var ns = result . Namespace ;
1418
- var firstExtent = result . FirstExtent ;
1419
- var lastExtent = result . LastExtent ;
1420
- var extentCount = result . ExtentCount ;
1421
- var dataSize = result . DataSize ;
1422
- var nrecords = result . RecordCount ;
1423
- var lastExtentSize = result . LastExtentSize ;
1424
- var padding = result . Padding ;
1425
- var firstExtentDetails = result . FirstExtentDetails ;
1426
- var loc = firstExtentDetails . Loc ;
1427
- var xnext = firstExtentDetails . XNext ;
1428
- var xprev = firstExtentDetails . XPrev ;
1429
- var nsdiag = firstExtentDetails . NSDiag ;
1430
- var size = firstExtentDetails . Size ;
1431
- var firstRecord = firstExtentDetails . FirstRecord ;
1432
- var lastRecord = firstExtentDetails . LastRecord ;
1433
- var deletedCount = result . DeletedCount ;
1434
- var deletedSize = result . DeletedSize ;
1435
- var nindexes = result . IndexCount ;
1436
- var keysPerIndex = result . KeysPerIndex ;
1437
- var valid = result . IsValid ;
1438
- var errors = result . Errors ;
1439
- var warning = result . Warning ;
1433
+ using ( _database . RequestStart ( ) )
1434
+ {
1435
+ var instance = _server . RequestConnection . ServerInstance ;
1436
+ if ( instance . InstanceType != MongoServerInstanceType . ShardRouter )
1437
+ {
1438
+ // ensure collection exists
1439
+ _collection . RemoveAll ( ) ;
1440
+ _collection . Insert ( new BsonDocument ( "x" , 1 ) ) ;
1441
+
1442
+ var result = _collection . Validate ( ) ;
1443
+ var ns = result . Namespace ;
1444
+ var firstExtent = result . FirstExtent ;
1445
+ var lastExtent = result . LastExtent ;
1446
+ var extentCount = result . ExtentCount ;
1447
+ var dataSize = result . DataSize ;
1448
+ var nrecords = result . RecordCount ;
1449
+ var lastExtentSize = result . LastExtentSize ;
1450
+ var padding = result . Padding ;
1451
+ var firstExtentDetails = result . FirstExtentDetails ;
1452
+ var loc = firstExtentDetails . Loc ;
1453
+ var xnext = firstExtentDetails . XNext ;
1454
+ var xprev = firstExtentDetails . XPrev ;
1455
+ var nsdiag = firstExtentDetails . NSDiag ;
1456
+ var size = firstExtentDetails . Size ;
1457
+ var firstRecord = firstExtentDetails . FirstRecord ;
1458
+ var lastRecord = firstExtentDetails . LastRecord ;
1459
+ var deletedCount = result . DeletedCount ;
1460
+ var deletedSize = result . DeletedSize ;
1461
+ var nindexes = result . IndexCount ;
1462
+ var keysPerIndex = result . KeysPerIndex ;
1463
+ var valid = result . IsValid ;
1464
+ var errors = result . Errors ;
1465
+ var warning = result . Warning ;
1466
+ }
1467
+ }
1440
1468
}
1441
1469
}
1442
1470
}
0 commit comments