I like to perform a set up before each time I run a unit test and clear my mongo db, how do I do it with mongoid?
I found some links about it while googling but nothing seemed to work.
Output of rake -T
rake db:drop # Drops all the collections for the database for the current Rails.env
..
rake db:mongoid:drop # Drops the database for the current Rails.env
rake db:mongoid:purge # Drop all collections except the system collections
..
rake db:purge # Drop all collections except the system collections
This discussion(Delete All Collections in Mongoid 3) in mongoid group seems relevant. There are two methods purge!
and truncate!
. Purge drops the collections, which means also the indexes. Truncate only drops the documents in each collection, which means you retain indexes, but it is slower than purge.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With