Merge pull request #343 from andreale/support_for_mongodb_3_wired_tiger

Fix truncation on MongoDB 3
This commit is contained in:
Ernesto Tagwerker 2015-06-28 13:42:23 -03:00
commit f86e4f00ab
2 changed files with 13 additions and 3 deletions

View file

@ -25,6 +25,10 @@ module DatabaseCleaner
@host ||= '127.0.0.1:27017'
end
def db_version
@db_version ||= session.command('buildinfo' => 1)['version']
end
private
def session

View file

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