@@ -46,7 +46,7 @@ public ListIndexesOperation(
4646 ReadPreference readPreference ,
4747 BsonBinaryReaderSettings readerSettings ,
4848 BsonBinaryWriterSettings writerSettings )
49- {
49+ {
5050 if ( string . IsNullOrEmpty ( databaseName ) )
5151 {
5252 throw new ArgumentException ( "Database name cannot be null or empty." , "databaseName" ) ;
@@ -95,7 +95,10 @@ public IEnumerable<BsonDocument> Execute(MongoConnection connection)
9595
9696 private IEnumerable < BsonDocument > ExecuteUsingCommand ( MongoConnection connection )
9797 {
98- var command = new CommandDocument ( "listIndexes" , _collectionName ) ;
98+ var command = new CommandDocument
99+ {
100+ { "listIndexes" , _collectionName }
101+ } ;
99102 var flags = QueryFlags . None ;
100103 var options = new BsonDocument ( ) ;
101104 IBsonSerializationOptions serializationOptions = null ;
@@ -118,7 +121,29 @@ private IEnumerable<BsonDocument> ExecuteUsingCommand(MongoConnection connection
118121 throw ;
119122 }
120123
121- return result . Response [ "indexes" ] . AsBsonArray . Cast < BsonDocument > ( ) ;
124+
125+ var cursorDocument = result . Response [ "cursor" ] ;
126+ var cursorId = cursorDocument [ "id" ] . ToInt64 ( ) ;
127+ var firstBatch = cursorDocument [ "firstBatch" ] . AsBsonArray . Select ( v => v . AsBsonDocument ) ;
128+ var ns = cursorDocument [ "ns" ] . ToString ( ) ;
129+ using ( var enumerator = new CursorEnumerator < BsonDocument > (
130+ new ServerInstanceConnectionProvider ( connection . ServerInstance ) ,
131+ ns ,
132+ firstBatch ,
133+ cursorId ,
134+ 0 ,
135+ 0 ,
136+ _readerSettings ,
137+ BsonDocumentSerializer . Instance ,
138+ null ) )
139+ {
140+ var collections = new List < BsonDocument > ( ) ;
141+ while ( enumerator . MoveNext ( ) )
142+ {
143+ collections . Add ( enumerator . Current ) ;
144+ }
145+ return collections ;
146+ }
122147 }
123148
124149 private IEnumerable < BsonDocument > ExecuteUsingQuery ( MongoConnection connection )
0 commit comments