Skip to content

Commit d70119c

Browse files
committed
RUBY-843 listCollections command can return a cursor
1 parent 6079140 commit d70119c

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

lib/mongo/db.rb

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,22 @@ def collections_info(coll_name=nil)
289289
if @client.wire_version_feature?(Mongo::MongoClient::MONGODB_2_8)
290290
cmd = BSON::OrderedHash[:listCollections, 1]
291291
cmd.merge!(:filter => { :name => coll_name }) if coll_name
292-
self.command(cmd)['collections']
292+
result = self.command(cmd)
293+
if result.key?('cursor')
294+
cursor_info = result['cursor']
295+
pinned_pool = @connection.pinned_pool
296+
pinned_pool = pinned_pool[:pool] if pinned_pool.respond_to?(:keys)
297+
298+
seed = {
299+
:cursor_id => cursor_info['id'],
300+
:first_batch => cursor_info['firstBatch'],
301+
:pool => pinned_pool
302+
}
303+
304+
Cursor.new(self, seed.merge!(opts)).collect { |doc| doc['collections'] }
305+
else
306+
result['collections']
307+
end
293308
else
294309
legacy_collections_info(coll_name).to_a
295310
end

0 commit comments

Comments
 (0)