Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 36 additions & 4 deletions lib/mongo/db.rb
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,23 @@ 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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You have to pass :cursor => {} as well.

self.command(cmd)['collections']
result = self.command(cmd, :cursor => {})
if result.key?('cursor')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To make it easier to rip out later, I'd look for "collections" instead.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for now, it works better this way because otherwise it'd be ugly:

if result['collections']
  return result['collections']
else
  ....

(currently, the block of code in the else statement is what I return)

cursor_info = result['cursor']
pinned_pool = @connection.pinned_pool
pinned_pool = pinned_pool[:pool] if pinned_pool.respond_to?(:keys)

seed = {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You also need to use the 'ns' field for OP_GET_MORE.

:cursor_id => cursor_info['id'],
:first_batch => cursor_info['firstBatch'],
:pool => pinned_pool,
:ns => cursor_info['ns']
}

Cursor.new(self, seed.merge!(opts)).collect { |doc| doc['collections'] }
else
result['collections']
end
else
legacy_collections_info(coll_name).to_a
end
Expand Down Expand Up @@ -493,11 +509,27 @@ 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 }, :cursor => {})
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,
:ns => cursor_info['ns']
}

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
Expand Down