Rails 3.2.1
app name: demo
database: mongoDB with mongoid
I have this scaffolding set up in rails 3.2.1: localhost:3000/pages,
and I have these fields: title, content.
I have already filled in 3 rows of data to each field.
The problem is: after deleting the app(by removing the root folder) and creating the same app name(demo) with the same scaffolding(pages), those 3 rows of data remain showing up which I don't want anymore.
Can anyone how to clean the database up?Thanks
the simplest way that i'm aware of is
rake db:mongoid:drop
as others said, you can go to rake --tasks and see it as well
The database exists outside your application, so deleting your application will not affect it. To empty or delete it you need to use the mongo command line or another mongo tool. Open up a terminal / command prompt and type:
mongo
And you should get the mongo command line. Switch to the DB for your app (it will most likely be of the form [app_name]_[environment]
:
use demo_development
And use the dropDatabase command:
db.dropDatabase()
Here is a quick snippet of how you can define a task, called db_reset, in your application namespace. It will drop both system and Mongo DBs given that MongoId gem is properly installed
lib/tasks/app_name.rake:
namespace Rails.application.class.parent do
desc 'Drops and recreates both Mongo and system databases for the current environment and loads the seeds.'
task db_reset: :environment do
Rake::Task['db:mongoid:purge'].invoke
Rake::Task['db:reset'].invoke
end
end
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.