mongoid Rails mongodb 数据未清理

发布于 2025-01-08 04:13:28 字数 313 浏览 4 评论 0原文

Rails 3.2.1

应用程序名称:演示

数据库:mongoDB 和 mongoid

我在 Rails 3.2.1 中设置了这个脚手架:localhost:3000/pages,

我有这些字段:标题、内容。

我已经在每个字段中填写了 3 行数据。

问题是:删除应用程序(通过删除根文件夹)并使用相同的脚手架(页面)创建相同的应用程序名称(演示)后,这 3 行数据仍然显示,而我不再想要了。

任何人都可以如何清理数据库吗?谢谢

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

烟柳画桥 2025-01-15 04:13:28

我知道的最简单的方法是

rake db:mongoid:drop

正如其他人所说,您也可以去 rake --tasks 并查看它

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

依 靠 2025-01-15 04:13:28

该数据库存在于您的应用程序之外,因此删除您的应用程序不会影响它。要清空或删除它,您需要使用 mongo 命令行或其他 mongo 工具。打开终端/命令提示符并输入:

mongo

您应该获得 mongo 命令行。切换到您的应用程序的数据库(它很可能采用 [app_name]_[environment] 形式:

use demo_development

并使用 dropDatabase 命令:

db.dropDatabase()

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()
黒涩兲箜 2025-01-15 04:13:28

以下是如何在应用程序命名空间中定义名为 db_reset 的任务的快速片段。如果 MongoId gem 已正确安装,它将删除系统和 Mongo DB

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

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
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文