Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix truncation on MongoDB 3 #343

Merged
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
15 changes: 12 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,18 @@ 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)['cursor']['firstBatch'].map do |collection|
collection['name']
end
.reject do |collection_name|
collection_name =~ /\.system\.|\$/

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This regexp isn't matching system.<something> collections. It should be collection_name =~ /.?system\.|\$/

For MongoDB 3.x.x using Wired Tiger storage engine this PR is sufficient, because by default there are no .system. collections. But if using MongoDB 3.x.x with MMapV1 storage engine, it will fail, because there still is the system.indexes collection.

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