Skip system collections at mongo-level rather than using reject

Relaxed regexp: skips collections like `<database_name>.$cmd`
This commit is contained in:
Alessandro Andreani 2015-04-20 12:32:40 +02:00
parent 0917ac10b8
commit ecc2951c59

View file

@ -24,12 +24,9 @@ module DatabaseCleaner
end
if db_version.split('.').first.to_i >= 3
session.command(listCollections: 1)['cursor']['firstBatch'].map do |collection|
session.command(listCollections: 1, filter: { 'name' => { '$not' => /.?system\.|\$/ } })['cursor']['firstBatch'].map do |collection|
collection['name']
end
.reject do |collection_name|
collection_name =~ /\.system\.|\$/
end
else
session['system.namespaces'].find(name: { '$not' => /\.system\.|\$/ }).to_a.map do |collection|
_, name = collection['name'].split('.', 2)