简体   繁体   English

将Activerecord数据库迁移到Mongoid

[英]Migrating an Activerecord database to Mongoid

I'm new to Rails programming. 我是Rails编程的新手。 I was thinking about implementing devise and omniauth authentication per railscast tutorial . 我正在考虑根据railscast教程实施devise和omniauth身份验证。 Since I don't know mongoid yet, I was planning on just starting with Activerecord. 由于我还不了解蒙古语,因此我打算从Activerecord开始。 Eventually I want to use Mongoid I think. 最终我想使用我认为的Mongoid。

How would I do a migration from Activerecord to Mongoid? 我该如何从Activerecord迁移到Mongoid?

I just want to get rolling with my project. 我只是想让我的项目进展顺利。 Especially when I have few users Activerecord will probably be sufficient. 特别是当我的用户很少时,Activerecord可能就足够了。 I've never done this before, so hopefully someone can tell me if this approach is going to be way more trouble than it's worth. 我以前从未做过此事,因此希望有人可以告诉我这种方法是否会带来更多麻烦而不是值得的。 Does it make more sense for me to take more time now to learn mongoid now instead? 现在花更多的时间学习蒙古语对我来说更有意义吗?

I'm looking forward to hearing from you Rails veterans. 我期待着您的Rails资深人士的来信。

You build your models, controllers and views exactly the using mongoid as you do using ActiveRecord, so there's little difference there. 就像使用ActiveRecord一样,您完全可以使用蒙古模型来构建模型,控制器和视图,因此两者之间几乎没有什么区别。 The big difference is in the way your data is actually stored and retrieved, which affects your models, which directly impacts your code. 最大的区别在于数据的实际存储和检索方式,这会影响您的模型,而这会直接影响您的代码。

A schema-less database like mongoDB can't protect you like MySQL can, and there is no simple way to do migrations using Mongoid. 像mongoDB这样的无模式数据库无法像MySQL那样保护您,并且没有使用Mongoid进行迁移的简单方法。

If you're starting out, you should probably go with ActiveRecord just because the a lot of the information out there relies on you using ActiveRecord with a relational database. 如果刚开始,您可能应该选择ActiveRecord,因为那里的很多信息都依赖于将ActiveRecord与关系数据库一起使用。

However, a switch to mongo/mongoid is definitely worth any perceived pain, but unless you've used a relational database and ActiveRecord, you may not appreciate just how awesome mongo/mongoid can be! 但是,切换到mongo / mongoid绝对值得您付出任何痛苦,但是,除非您使用了关系数据库和ActiveRecord,否则您可能不会欣赏mongo / mongoid的出色表现!

...and there is no simple way to do migrations using Mongoid. ...没有简单的方法可以使用Mongoid进行迁移。

This isn't true. 这不是真的 It is actually quite simple to create migrations in Mongoid. 在Mongoid中创建迁移实际上非常简单。 If you want to add a column to a database table, simply add it as a "field" to the top of the Model class like so: 如果要向数据库表中添加列,只需将其作为“字段”添加到Model类的顶部,如下所示:

class User
  include Mongoid::Document

  field :email, type: String
  field :phone, type: String
  field :reputation, type: Integer
end

No creating migrations, no raking the database. 不创建迁移,不耙数据库。 Just add/remove fields as needed, restart the server, and you're good to go. 只需根据需要添加/删除字段,然后重新启动服务器即可。 You should however be wary of removing fields as they can break your code where you referenced them. 但是,您应该警惕删除字段,因为它们会破坏引用它们的代码。

I believe ActiveRecord is sufficient. 我相信ActiveRecord就足够了。 And please think about those small gems/plugins which are handy but not able to work with Mongoid. 并且请考虑那些方便但无法与Mongoid一起使用的小型宝石/插件。 Tutorials, screencasts - vast majority of them are based on default ORM/Mysql. 教程,屏幕录像-绝大多数基于默认的ORM / Mysql。

For now it's just not worth to spent time on Mongoid I think. 我认为,现在暂时不花时间在Mongoid上是不值得的。

暂无
暂无

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

相关问题 在将Rails应用程序从mongoid(MongoDB)迁移到ActiveRecord(Postgres)时如何获得恒定的内存使用量? - How to obtain constant memory usage when migrating a Rails application from mongoid (MongoDB) to ActiveRecord (Postgres)? rspec with mongoid,devise,database_cleaner:ActiveRecord :: ConnectionNotEstablished error - rspec with mongoid, devise, database_cleaner : ActiveRecord::ConnectionNotEstablished error 有关从MongoMapper迁移到Mongoid的建议? - Advice on migrating from MongoMapper to Mongoid? ActiveRecord::ConnectionNotEstablished: ActiveRecord::Base with mongoid 没有连接池 - ActiveRecord::ConnectionNotEstablished: No connection pool for ActiveRecord::Base with mongoid 如何用ActiveRecord或Mongoid编写此查询? - How to write this query with ActiveRecord or Mongoid? 使用database_cleaner,mongoid和active_admin导致规范失败并使用ActiveRecord :: ConnectionNotEstablished - Using database_cleaner, mongoid and active_admin causes specs to fail with ActiveRecord::ConnectionNotEstablished 我可以在ActiveRecord(或Mongoid)中为数据库连接和table_name配置线程安全的每个请求配置吗? - Can I have thread safe per-request configuration for database connection and table_name in ActiveRecord (or Mongoid)? mongoId的ActiveRecord的any_of实现的问题 - Issue with mongoId's any_of implementation for activerecord Mongoid中的ActiveRecord#Establishment_connection等效项是什么? - what is the equivalent of ActiveRecord#establish_connection in Mongoid? 将Mongoid转换为ActiveRecord以进行Devise-Basecamp设置 - Converting Mongoid to ActiveRecord for Devise-Basecamp setup
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM