Thursday, April 3, 2014

Dropping a database after running rspec tests with MongoMapper or Mongoid

The mongodb folder on my development computer was using 11 gb, and I needed to free up some space on /var, since that was on the / partition. (Yes, it is recommended to have it on separate partition, but that is another discussion).

In your rspec add this:

RSpec.configure do |config|
  config.after(:suite) do
    # for MongoMapper
    db = MongoMapper.database
    # for Mongoid
    # db = Mongoid.master
    # drop the database

For using mongo directly, you need to access the db object and trigger the command as above.