Reputation: 30231
My current rails app is backed by mongoid/mongo. Between each test I want to clear the database. To this I run
::Mongoid.database.collections.select { |c| c.name !~ /^system/ }.each { |c| c.remove() }
Problem is the removal of the collection seems to run in the background. Sometimes the next test will start, insert a document and then have it cleared by the remove operation. Is there any way to make the collection removal blocking?
I understand there is an $atomic option, having looked at the source for mongo/collection I can't see any way to pass the option in. How can I make the collcetion removal blocking?
Upvotes: 0
Views: 673
Reputation: 6856
Mongoid when you call remove, simply passes what you send as arguments to the underlying mongo ruby driver. From API documentation http://api.mongodb.org/ruby/1.2.1/Mongo/Collection.html#remove-instance_method safe=>true blocks until it is done. So:
::Mongoid.database.collections.select { |c| c.name !~ /^system/ }.each { |c| c.remove(:safe => true) }
Upvotes: 1