@@ -261,8 +261,6 @@ public void Download(Stream stream, MongoGridFSFileInfo fileInfo)
261
261
262
262
using ( _database . RequestStart ( _database . Settings . SlaveOk ) )
263
263
{
264
- EnsureIndexes ( ) ;
265
-
266
264
string md5Client = null ;
267
265
using ( var md5Algorithm = _settings . VerifyMD5 ? MD5 . Create ( ) : null )
268
266
{
@@ -325,7 +323,6 @@ public void Download(Stream stream, string remoteFileName)
325
323
/// <param name="version">The version to download.</param>
326
324
public void Download ( Stream stream , string remoteFileName , int version )
327
325
{
328
- EnsureIndexes ( ) ;
329
326
Download ( stream , Query . EQ ( "filename" , remoteFileName ) , version ) ;
330
327
}
331
328
@@ -423,25 +420,10 @@ public void EnsureIndexes()
423
420
/// <param name="maxFiles">Only create new indexes if there are fewer than this number of GridFS files).</param>
424
421
public void EnsureIndexes ( int maxFiles )
425
422
{
426
- // don't try to create indexes on secondaries
427
- var requestConnection = _database . Server . RequestConnection ;
428
- if ( requestConnection != null )
429
- {
430
- // check whether the actual server instance we are using is a primary
431
- var serverInstance = requestConnection . ServerInstance ;
432
- if ( ! serverInstance . IsPrimary )
433
- {
434
- return ;
435
- }
436
- }
437
- else
438
- {
439
- // check whether we are guaranteed to use a primary
440
- if ( _database . Settings . SlaveOk )
441
- {
442
- return ;
443
- }
444
- }
423
+ // EnsureIndexes should only be called for update operations
424
+ // read-only operations shouldn't call EnsureIndexes because:
425
+ // 1. we might be reading from a secondary
426
+ // 2. we might be authenticating as a read-only uaser
445
427
446
428
// avoid round trip to count files if possible
447
429
var indexCache = _database . Server . IndexCache ;
@@ -489,7 +471,6 @@ public bool Exists(IMongoQuery query)
489
471
/// <returns>True if the GridFS file exists.</returns>
490
472
public bool Exists ( string remoteFileName )
491
473
{
492
- EnsureIndexes ( ) ;
493
474
return Exists ( Query . EQ ( "filename" , remoteFileName ) ) ;
494
475
}
495
476
@@ -521,7 +502,6 @@ public MongoCursor<MongoGridFSFileInfo> Find(IMongoQuery query)
521
502
/// <returns>The matching GridFS files.</returns>
522
503
public MongoCursor < MongoGridFSFileInfo > Find ( string remoteFileName )
523
504
{
524
- EnsureIndexes ( ) ;
525
505
return Find ( Query . EQ ( "filename" , remoteFileName ) ) ;
526
506
}
527
507
@@ -594,7 +574,6 @@ public MongoGridFSFileInfo FindOne(string remoteFileName)
594
574
/// <returns>The matching GridFS file.</returns>
595
575
public MongoGridFSFileInfo FindOne ( string remoteFileName , int version )
596
576
{
597
- EnsureIndexes ( ) ;
598
577
return FindOne ( Query . EQ ( "filename" , remoteFileName ) , version ) ;
599
578
}
600
579
0 commit comments