Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Clear db with mongoid3

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.

like image 337
Chen Kinnrot Avatar asked Feb 18 '23 14:02

Chen Kinnrot


2 Answers

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
like image 177
Santhosh Avatar answered Mar 04 '23 06:03

Santhosh


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.

like image 20
rubish Avatar answered Mar 04 '23 08:03

rubish