Skip to content

Commit d5207cd

Browse files
committed
RUBY-843 listIndexes command can return a cursor
1 parent d70119c commit d5207cd

File tree

1 file changed

+18
-3
lines changed

1 file changed

+18
-3
lines changed

lib/mongo/db.rb

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -508,11 +508,26 @@ def drop_index(collection_name, index_name)
508508
# defining the index.
509509
def index_information(collection_name)
510510
if @client.wire_version_feature?(Mongo::MongoClient::MONGODB_2_8)
511-
result = self.command(:listIndexes => collection_name)['indexes']
511+
result = self.command(:listIndexes => collection_name)
512+
if result.key?('cursor')
513+
cursor_info = result['cursor']
514+
pinned_pool = @connection.pinned_pool
515+
pinned_pool = pinned_pool[:pool] if pinned_pool.respond_to?(:keys)
516+
517+
seed = {
518+
:cursor_id => cursor_info['id'],
519+
:first_batch => cursor_info['firstBatch'],
520+
:pool => pinned_pool
521+
}
522+
523+
indexes = Cursor.new(self, seed.merge!(opts)).collect { |doc| doc['indexes'] }
524+
else
525+
indexes = result['indexes']
526+
end
512527
else
513-
result = legacy_list_indexes(collection_name)
528+
indexes = legacy_list_indexes(collection_name)
514529
end
515-
result.reduce({}) do |info, index|
530+
indexes.reduce({}) do |info, index|
516531
info.merge!(index['name'] => index)
517532
end
518533
end

0 commit comments

Comments
 (0)