mirror of
https://github.com/DatabaseCleaner/database_cleaner
synced 2023-03-27 23:22:03 -04:00
Merge pull request #343 from andreale/support_for_mongodb_3_wired_tiger
Fix truncation on MongoDB 3
This commit is contained in:
commit
f86e4f00ab
2 changed files with 13 additions and 3 deletions
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
Loading…
Reference in a new issue