简体   繁体   English

mongodb rails mongodb数据未清除

[英]mongoid rails mongodb data not cleaning up

Rails 3.2.1 导轨3.2.1

app name: demo 应用名称:演示

database: mongoDB with mongoid 数据库:mongoDB与mongoid

I have this scaffolding set up in rails 3.2.1: localhost:3000/pages, 我在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. 我已经在每个字段中填充了3行数据。

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 正如其他人所说,您可以进行rake --tasks并查看它

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. 要清空或删除它,您需要使用mongo命令行或其他mongo工具。 Open up a terminal / command prompt and type: 打开终端/命令提示符,然后键入:

mongo

And you should get the mongo command line. 并且您应该获得mongo命令行。 Switch to the DB for your app (it will most likely be of the form [app_name]_[environment] : 切换到您的应用程序的数据库(它很可能采用[app_name]_[environment]

use demo_development

And use the dropDatabase command: 并使用dropDatabase命令:

db.dropDatabase()

Here is a quick snippet of how you can define a task, called db_reset, in your application namespace. 以下是如何在应用程序名称空间中定义名为db_reset的任务的快速摘要。 It will drop both system and Mongo DBs given that MongoId gem is properly installed 如果正确安装了MongoId gem,它将同时删除系统数据库和Mongo数据库

lib/tasks/app_name.rake: 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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM