Skip to content

Commit

Permalink
Merge pull request #343 from andreale/support_for_mongodb_3_wired_tiger
Browse files Browse the repository at this point in the history
Fix truncation on MongoDB 3
  • Loading branch information
etagwerker committed Jun 28, 2015
2 parents 19773bb + ecc2951 commit f86e4f0
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
4 changes: 4 additions & 0 deletions lib/database_cleaner/moped/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ def host
@host ||= '127.0.0.1:27017'
end

def db_version
@db_version ||= session.command('buildinfo' => 1)['version']
end

private

def session
Expand Down
12 changes: 9 additions & 3 deletions lib/database_cleaner/moped/truncation_base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,15 @@ def collections
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

Expand Down

0 comments on commit f86e4f0

Please sign in to comment.