1

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.

1 Answer 1

1

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

Sign up to request clarification or add additional context in comments.

10 Comments

Can you please say how to insert data into a mongodb server from command or a rails app.Everthing above worked fine.Thank you
Thank you.Started learning CRUD and created my first collection.Then,how to retrieve data into my rails controller from mongoDB collections.
For example: Person.where(first_name: "Heinrich")
How to configure our rails server to take data from mongoDB.
@ashr81 you should modify the mongoid.yml, you can get more detail info from here
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.