From d70119cc10618b2a7073105058027fb847c29b70 Mon Sep 17 00:00:00 2001 From: Emily Stolfo Date: Fri, 12 Dec 2014 13:56:13 +0100 Subject: [PATCH 1/3] RUBY-843 listCollections command can return a cursor --- lib/mongo/db.rb | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/lib/mongo/db.rb b/lib/mongo/db.rb index 35c10f2cd0..a91d84e5ff 100644 --- a/lib/mongo/db.rb +++ b/lib/mongo/db.rb @@ -289,7 +289,22 @@ def collections_info(coll_name=nil) if @client.wire_version_feature?(Mongo::MongoClient::MONGODB_2_8) cmd = BSON::OrderedHash[:listCollections, 1] cmd.merge!(:filter => { :name => coll_name }) if coll_name - self.command(cmd)['collections'] + result = self.command(cmd) + if result.key?('cursor') + cursor_info = result['cursor'] + pinned_pool = @connection.pinned_pool + pinned_pool = pinned_pool[:pool] if pinned_pool.respond_to?(:keys) + + seed = { + :cursor_id => cursor_info['id'], + :first_batch => cursor_info['firstBatch'], + :pool => pinned_pool + } + + Cursor.new(self, seed.merge!(opts)).collect { |doc| doc['collections'] } + else + result['collections'] + end else legacy_collections_info(coll_name).to_a end From d5207cdcef73333218ef85148bf6cc881b412937 Mon Sep 17 00:00:00 2001 From: Emily Stolfo Date: Fri, 12 Dec 2014 14:16:12 +0100 Subject: [PATCH 2/3] RUBY-843 listIndexes command can return a cursor --- lib/mongo/db.rb | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/lib/mongo/db.rb b/lib/mongo/db.rb index a91d84e5ff..7aaf6174e1 100644 --- a/lib/mongo/db.rb +++ b/lib/mongo/db.rb @@ -508,11 +508,26 @@ def drop_index(collection_name, index_name) # defining the index. def index_information(collection_name) if @client.wire_version_feature?(Mongo::MongoClient::MONGODB_2_8) - result = self.command(:listIndexes => collection_name)['indexes'] + result = self.command(:listIndexes => collection_name) + if result.key?('cursor') + cursor_info = result['cursor'] + pinned_pool = @connection.pinned_pool + pinned_pool = pinned_pool[:pool] if pinned_pool.respond_to?(:keys) + + seed = { + :cursor_id => cursor_info['id'], + :first_batch => cursor_info['firstBatch'], + :pool => pinned_pool + } + + indexes = Cursor.new(self, seed.merge!(opts)).collect { |doc| doc['indexes'] } + else + indexes = result['indexes'] + end else - result = legacy_list_indexes(collection_name) + indexes = legacy_list_indexes(collection_name) end - result.reduce({}) do |info, index| + indexes.reduce({}) do |info, index| info.merge!(index['name'] => index) end end From 48322a084eec8505e92d6b0e5f98fa58df505022 Mon Sep 17 00:00:00 2001 From: Emily Stolfo Date: Fri, 19 Dec 2014 14:53:34 -0500 Subject: [PATCH 3/3] RUBY-843 Take ns into account and add cursor option to commands --- lib/mongo/db.rb | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/lib/mongo/db.rb b/lib/mongo/db.rb index 7aaf6174e1..d363689a3d 100644 --- a/lib/mongo/db.rb +++ b/lib/mongo/db.rb @@ -289,7 +289,7 @@ def collections_info(coll_name=nil) if @client.wire_version_feature?(Mongo::MongoClient::MONGODB_2_8) cmd = BSON::OrderedHash[:listCollections, 1] cmd.merge!(:filter => { :name => coll_name }) if coll_name - result = self.command(cmd) + result = self.command(cmd, :cursor => {}) if result.key?('cursor') cursor_info = result['cursor'] pinned_pool = @connection.pinned_pool @@ -298,7 +298,8 @@ def collections_info(coll_name=nil) seed = { :cursor_id => cursor_info['id'], :first_batch => cursor_info['firstBatch'], - :pool => pinned_pool + :pool => pinned_pool, + :ns => cursor_info['ns'] } Cursor.new(self, seed.merge!(opts)).collect { |doc| doc['collections'] } @@ -508,7 +509,7 @@ def drop_index(collection_name, index_name) # defining the index. def index_information(collection_name) if @client.wire_version_feature?(Mongo::MongoClient::MONGODB_2_8) - result = self.command(:listIndexes => collection_name) + result = self.command({ :listIndexes => collection_name }, :cursor => {}) if result.key?('cursor') cursor_info = result['cursor'] pinned_pool = @connection.pinned_pool @@ -517,7 +518,8 @@ def index_information(collection_name) seed = { :cursor_id => cursor_info['id'], :first_batch => cursor_info['firstBatch'], - :pool => pinned_pool + :pool => pinned_pool, + :ns => cursor_info['ns'] } indexes = Cursor.new(self, seed.merge!(opts)).collect { |doc| doc['indexes'] }