Skip to content

Commit bda9777

Browse files
committed
RUBY-1336 Ensure that system collections are not returned from listCollections
1 parent 8ea978c commit bda9777

File tree

2 files changed

+9
-0
lines changed

2 files changed

+9
-0
lines changed

lib/mongo/operation/list_collections/op_msg.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,11 @@ def execute(server)
4444

4545
private
4646

47+
def selector(server)
48+
(spec[SELECTOR] || {}).merge(
49+
listCollections: 1, filter: { name: { '$not' => /system\.|\$/ }})
50+
end
51+
4752
def message(server)
4853
Protocol::Msg.new(flags, options, command(server))
4954
end

spec/mongo/database_spec.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,10 @@
200200
it 'returns collection objects for each name' do
201201
expect(database.collections).to include(collection)
202202
end
203+
204+
it 'does not include the system collections' do
205+
expect(database.collections.collect(&:name).none? { |name| name =~ /system\.|\$/ }).to be(true)
206+
end
203207
end
204208

205209
context 'when the database does not exist' do

0 commit comments

Comments
 (0)