File tree Expand file tree Collapse file tree 5 files changed +65
-2
lines changed Expand file tree Collapse file tree 5 files changed +65
-2
lines changed Original file line number Diff line number Diff line change @@ -51,6 +51,7 @@ class View
51
51
def collection_names ( options = { } )
52
52
@batch_size = options [ :batch_size ]
53
53
server = next_primary
54
+ @limit = -1 if server . context . features . list_collections_enabled?
54
55
collections_info ( server ) . collect do |info |
55
56
server . context . features . list_collections_enabled? ?
56
57
info [ Database ::NAME ] : info [ Database ::NAME ] . sub ( "#{ @database . name } ." , '' )
@@ -80,7 +81,7 @@ def list_collections
80
81
def initialize ( database )
81
82
@database = database
82
83
@batch_size = nil
83
- @limit = - 1
84
+ @limit = nil
84
85
@collection = @database [ Database ::COMMAND ]
85
86
end
86
87
Original file line number Diff line number Diff line change 12
12
# See the License for the specific language governing permissions and
13
13
# limitations under the License.
14
14
15
+ require 'mongo/operation/commands/collections_info/result'
16
+
15
17
module Mongo
16
18
module Operation
17
19
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
110
110
def first_document
111
111
@first_document ||= reply . documents [ 0 ]
112
112
end
113
- end end
113
+ end
114
+ end
114
115
end
115
116
end
Original file line number Diff line number Diff line change 93
93
expect ( database . collection_names ( batch_size : 1 ) . to_a ) . to include ( 'users' )
94
94
end
95
95
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
96
116
end
97
117
98
118
describe '#list_collections' do
You can’t perform that action at this time.
0 commit comments