How to populate data into mongodb using rails?

假如想象 提交于 2019-12-08 06:03:37

问题


I'm new to rails application. I got connection with mongodb using mongoid. I generated the mongoid:migration using command called

rails generate migration sample

it creates,

db\migrate\20111222081138_sample.rb contains the following code

class Sample < Mongoid::Migration
   def self.up
      sample.create(first_name: "Heinrich", last_name: "Heine")
   end    

   def self.down
   end
end
my questions are
1.why schema.rb is not present in db.
2.how to populate data into mongodb using rails
3.how to list db collections in rails
4.how to produce bson file into rails

回答1:


MondoDB is a schema-less database, this is the reason why schema.rb is not present.

To query, insert, update or delete records, follow the instructions available in the Mongoid documentation. The documentation is comprehensive, well-written and it is worth a read.

Also, if you are completely new to Rails and you don't know almost anything about NoSQL databases, it's better if you start with one technology at time and you just try Rails with a relational database, such as SQLite or PostgreSQL.

The most part of Rails ORM tutorials is about ActiveRecord. Trying to approach several new topics at once just leads to confusion.




回答2:


I also encountered this problem I'm new on using rails with mongodb. The solution I found is to create db/seeds.rb manually. Add the dummy data there and run rails db:seed as usual. It works just fine for me.



来源:https://stackoverflow.com/questions/8602515/how-to-populate-data-into-mongodb-using-rails

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!