如何使用Rails将数据填充到mongodb中? [英] How to populate data into mongodb using rails?

查看:86
本文介绍了如何使用Rails将数据填充到mongodb中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是Rails应用程序的新手.我使用mongoid与mongodb建立了联系. 我使用名为

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

它创建,

db \ migrate \ 20111222081138_sample.rb包含以下代码

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

推荐答案

MondoDB是一个无模式数据库,这就是schema.rb不存在的原因.

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

要查询,插入,更新或删除记录,请按照 Mongoid文档中的说明进行操作.该文档内容详尽,编写精良,值得一读.

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.

此外,如果您是Rails的新手,并且对NoSQL数据库几乎一无所知,那么最好一次使用一种技术,而仅使用带有关系数据库(例如SQLite或PostgreSQL)的Rails会更好.

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.

Rails ORM教程的大部分内容都是关于ActiveRecord的.试图同时处理几个新主题只会引起混乱.

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

这篇关于如何使用Rails将数据填充到mongodb中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆