ashr81
ashr81

Reputation: 650

Ruby on Rails with Mongo DataBase

I am a neophyte in this topics. I have been trying to install and run MongoDB on my Windows OS.I installed MongoId

rails g mongoid:config

The above command is not creating config File. I created the file manually.I skipped the ActionController gem During Creation of App.To use mongoId Config file in rails app.

But,I am not sure how to start server in mongoDB. And insert Into it in Rails application.In most of the Blog Post they jumped out of this step.

The Documentation in MongoDB is not clear.Please,Help me in correct installation and starting,inserting and retrieving data from MongoDB in rails application on Windows OS.

Upvotes: 1

Views: 1271

Answers (1)

pangpang
pangpang

Reputation: 8821

At first, you should install MongoDB on Windows(refer to this link)

then add mongoid to Gemfile.

gem 'mongoid', '~> 5.0.0.beta'

run bundle install.

then run rails g mongoid:config to generate mongoid.yml

then start rails server by command rails server or rails s

Mongoid supports all expected CRUD operations for those familiar with other Ruby mappers like Active Record or Data Mapper

if you want to insert a document into the mongodb, you can do like this:

Person.create(
  first_name: "Heinrich",
  last_name: "Heine"
)

get document from mongodb:

Person.where(first_name: "Heinrich")

You can get more info from here

Upvotes: 1

Related Questions