Skip to content

Commit 8d8b03a

Browse files
committed
Merge pull request #690 from estolfo/RUBY-1025-collections-info
RUBY-1025 Make sure collections info returns all results
2 parents 2667e66 + f7b2e8c commit 8d8b03a

File tree

5 files changed

+66
-3
lines changed

5 files changed

+66
-3
lines changed

lib/mongo/database/view.rb

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,9 @@ class View
5151
def collection_names(options = {})
5252
@batch_size = options[:batch_size]
5353
server = next_primary
54+
@limit = -1 if server.features.list_collections_enabled?
5455
collections_info(server).collect do |info|
55-
server.context.features.list_collections_enabled? ?
56+
server.features.list_collections_enabled? ?
5657
info[Database::NAME] : info[Database::NAME].sub("#{@database.name}.", '')
5758
end
5859
end
@@ -80,7 +81,7 @@ def list_collections
8081
def initialize(database)
8182
@database = database
8283
@batch_size = nil
83-
@limit = -1
84+
@limit = nil
8485
@collection = @database[Database::COMMAND]
8586
end
8687

lib/mongo/operation/commands/collections_info.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15+
require 'mongo/operation/commands/collections_info/result'
16+
1517
module Mongo
1618
module Operation
1719

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# Copyright (C) 2014-2015 MongoDB, Inc.
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
module Mongo
16+
module Operation
17+
class CollectionsInfo
18+
19+
# Defines custom behaviour of results when query the system.namespaces
20+
# collection.
21+
#
22+
# @since 2.1.0
23+
class Result < Operation::Result
24+
25+
# Get the namespace for the cursor.
26+
#
27+
# @example Get the namespace.
28+
# result.namespace
29+
#
30+
# @return [ String ] The namespace.
31+
#
32+
# @since 2.1.0
33+
def namespace
34+
Database::NAMESPACES
35+
end
36+
end
37+
end
38+
end
39+
end

lib/mongo/operation/commands/list_indexes/result.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ def cursor_document
110110
def first_document
111111
@first_document ||= reply.documents[0]
112112
end
113-
end end
113+
end
114+
end
114115
end
115116
end

spec/mongo/database_spec.rb

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,26 @@
9393
expect(database.collection_names(batch_size: 1).to_a).to include('users')
9494
end
9595
end
96+
97+
context 'when there are more collections than the initial batch size' do
98+
99+
before do
100+
200.times do |i|
101+
database["#{i}_dalmatians"].create
102+
end
103+
end
104+
105+
after do
106+
200.times do |i|
107+
database["#{i}_dalmatians"].drop
108+
end
109+
end
110+
111+
it 'returns all collections' do
112+
expect(database.collection_names.select { |c| c =~ /dalmatians/}.size).to eq(200)
113+
end
114+
115+
end
96116
end
97117

98118
describe '#list_collections' do

0 commit comments

Comments
 (0)