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

Conversation

andreale
Copy link
Contributor

@andreale andreale commented Mar 6, 2015

As reported on the mongoDB documentation, the collection system.namespaces is deprecated and can no longer be used to list the database collections.

5ca89421407c3a033eed20b4997a64c6

This PR addresses the deprecation issue by using the command listCollections instead. This allow DatabaseCleaner to work with MongoDB 3 with WiredTiger storage engine.

@zjx20
Copy link

zjx20 commented Mar 20, 2015

Thanks! This really helps a whole lot!

@bejmuller
Copy link

+1

1 similar comment
@FlammenB
Copy link

FlammenB commented Apr 7, 2015

👍

@lifegiver
Copy link

🆗

@simonmorley
Copy link

+1

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.

@andreale
Copy link
Contributor Author

Hi @saschaknobloch, thanks for your feedback.

I just reused the (already present) regexp that filters out any xxxxxx.system.indexes and xxxxxx.yyyyyy.$_id_ collection. This should make my change also compatible with MMAPv1 collections (by excluding those collections form the truncation).

Could you please clarify better the issue?

@saschaknobloch
Copy link

Hey @andreale,

here is a link to rubular with the regexp provided with this code, check out yourself:

http://rubular.com/r/qpc2cGb38J

@saschaknobloch
Copy link

BTW: the command listCollections allows also for setting a filter

http://docs.mongodb.org/manual/reference/command/listCollections/#dbcmd.listCollections

This gives us the chance to solve this problem more elegant (but still the regex provided with this PR doesn't work for me ;) ):

session.command(listCollections: 1, filter: {"name"=> {"$not"=>/.?system\.|\$/}})['cursor']['firstBatch'].map do |collection| 
...
end 

Relaxed regexp: skips collections like `<database_name>.$cmd`
@andreale
Copy link
Contributor Author

Thanks @saschaknobloch.

I could reproduce the issue on another dev machine (where we also get a <database_name.$cmd collection) and confirm your updated regexp is working. I'm updating my PR, with also the filter at mongo-level.

  • Ale

@lucke84
Copy link

lucke84 commented May 20, 2015

+1

1 similar comment
@dot
Copy link

dot commented Jun 9, 2015

+1

@saschaknobloch
Copy link

Since there is no progress on supporting MongoDB 3, we've released our own implementation:

https://github.com/td-berlin/mongoid_cleaner

We've added drop strategy, which improves the performance (compared to truncation strategy) by factor 3-5 for our projects.

It only supports Mongoid and MongoDB 3. It's tested with:

  • Ruby 2.1
  • Ruby 2.2
  • JRuby
  • Ruby-Head

Each against WiredTiger and MMAPv1.

Feel free to use and contribute.

etagwerker added a commit that referenced this pull request Jun 28, 2015
@etagwerker etagwerker merged commit f86e4f0 into DatabaseCleaner:master Jun 28, 2015
@etagwerker
Copy link
Member

@andreale Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

10 participants