Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7957305
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T04:13:49+00:00 2026-06-04T04:13:49+00:00

basically I have a mongodb instance running and working on ec2. On the side

  • 0

basically I have a mongodb instance running and working on ec2. On the side I have a rails 3.2 app with mongoid as orm working on local. What I want to do next is try to connect my rails app to the mongodb instance using mongoid. Also, intending to host my rails app on Dotcloud later

Ran the code rails g mongoid:config to generate the mongoid.yml file with the following code:

development:
 host: localhost
 database: mongotest_development

test:
 host: localhost
 database: mongotest_test

set these environment variables on your prod server
production:
 host: <%= ENV['MONGOID_HOST'] %>
 port: <%= ENV['MONGOID_PORT'] %>
 username: <%= ENV['MONGOID_USERNAME'] %>
 password: <%= ENV['MONGOID_PASSWORD'] %>
 database: <%= ENV['MONGOID_DATABASE'] %>
 # slaves:
 #   - host: slave1.local
 #     port: 27018
 #   - host: slave2.local
 #     port: 27019

From here onwards, I don’t think I have a clear picture of how all this is going to work. But I did some trial and error. Firstly I wanted to try connecting to the mongodb instance on development, so I commented out the mongoid.yml defaults and added the following:

development:
 host: <public dns of the mongodb instance>
 port: 27017
 # username: 
 # password: 
 database: <I ssh into the instance and created a database>

I commented the username and password out partly because I am not sure what to put, and partly because when I inspect the mongod.conf file on ec2, I saw that by default :auth is false, so I assume authentication is not required. So I ran rails console and got the following error:

Failed to connect to a master node at <public dns of the mongodb instance>:27017 (Mongo::ConnectionFailure)
from /Users/Kinglee/.rvm/gems/ruby-1.9.2-p180@rails3tutorial/gems/mongo-1.6.2/lib/mongo/connection.rb:589:in `setup'
from /Users/Kinglee/.rvm/gems/ruby-1.9.2-p180@rails3tutorial/gems/mongo-1.6.2/lib/mongo/connection.rb:114:in `initialize'
from /Users/Kinglee/.rvm/gems/ruby-1.9.2-p180@rails3tutorial/gems/mongo-1.6.2/lib/mongo/connection.rb:165:in `new'
from /Users/Kinglee/.rvm/gems/ruby-1.9.2-p180@rails3tutorial/gems/mongo-1.6.2/lib/mongo/connection.rb:165:in `from_uri'
from /Users/Kinglee/.rvm/gems/ruby-1.9.2-p180@rails3tutorial/gems/mongoid-2.4.10/lib/mongoid/config/database.rb:86:in `master'
from /Users/Kinglee/.rvm/gems/ruby-1.9.2-p180@rails3tutorial/gems/mongoid-2.4.10/lib/mongoid/config/database.rb:19:in `configure'
from /Users/Kinglee/.rvm/gems/ruby-1.9.2-p180@rails3tutorial/gems/mongoid-2.4.10/lib/mongoid/config.rb:290:in `configure_databases'
....

At this point, I am kind of confused. I kept asking myself, do I need the username and password to connect to mongodb ? I kind of 80% sure that I need them but I am not sure where to find them or rather not sure what am I connecting to, the mongodb ec2 instance or the mongodb database. How should I go about doing that ? Should I open port 27017 and 28017 on the instance ? Do I need to add config to database.yml (I highly doubt I need to since there is already mongoid.yml but just want to confirm)

I have been looking at a list of documentation and tutorial:

  • http://mongoid.org/docs/installation/configuration.html
  • http://www.mongodb.org/display/DOCS/Security+and+Authentication#SecurityandAuthentication-AbouttheKeyFile
  • MongoDB and Mongoid in production – looks like what I looking for, but not sure, going to try it.
  • http://craiccomputing.blogspot.com/2011/02/authentication-in-mongo-and-mongoid.html

Appreciate any advice from anyone here.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T04:13:50+00:00Added an answer on June 4, 2026 at 4:13 am

    Ok finally found the problem. In the mongodb.conf file, there is a setting which called

    bind_ip = 127.0.0.1
    

    I was blind to not notice this, it means that the server can only be access locally and not externally, hence the fail connection error. A quick fix would be to change it to

    bind_ip = 0.0.0.0
    

    and it works. But thanks for the advice guys.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I basically have the core data and the app working correctly except for the
I basically have a unix process running and it is doing some heavy processing
Recently I've been working a little with MongoDB and I have to say I
I have a relatively simple case. I basically want to store data about links
I basically have a database and an application, and what i want to do
I basically have three tables, posts, images and postimages (this simply contains the ids
I basically have a server set up and I'm accepting new clients(UNIX) and i'm
I basically have the following string in the format: A,B,C:D,E,F What I am trying
I basically have 7 select statements that I need to have the results output
I basically have to do a update of a record. I have a set

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.