File tree Expand file tree Collapse file tree 5 files changed +66
-3
lines changed Expand file tree Collapse file tree 5 files changed +66
-3
lines changed Original file line number Diff line number Diff 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
Original file line number Diff line number Diff line change 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+
1517module Mongo
1618 module Operation
1719
Original file line number Diff line number Diff line change 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
Original file line number Diff line number Diff 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
115116end
Original file line number Diff line number Diff line change 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
You can’t perform that action at this time.
0 commit comments