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

  • Home
  • SEARCH
  • 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 3499972
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T12:40:36+00:00 2026-05-18T12:40:36+00:00

This is just for my weekend project/study, I am very new to Sinatra and

  • 0

This is just for my weekend project/study, I am very new to Sinatra and MongoDB.

I’ve installed the gems for mongoDB, such as: mongo, mongo_mapper and mongoid.

When I tried connecting to my database on MongoHQ from localhost, it encountered such an error:

Mongo::ConnectionFailure at /
failed to connect to any given host:port

    * file: connection.rb
    * location: connect
    * line: 489

I found a similar thread on SO, but frankly speaking, I don’t quite understand the answers…

Here is my code snippet:

require 'rubygems'
require 'sinatra'
require 'mongo'
require 'mongo_mapper'

get '/' do
  MongoMapper.connection = Mongo::Connection.new('flame.mongohq.com', 27044)
  MongoMapper.database = 'notes'
  MongoMapper.database.authenticate('foo', 'bar')
  erb :list
end

I took the above code from here, but it seems not working…

Which part is wrong? Is there another way to do this? In the end this test web app will be deployed onto heroku, so I hope the solution can work with both localhost and my heroku server.

Updated:

I just created a minimal code snippet to test the mongodb connection:
require 'rubygems'
require 'mongo'

db = Mongo::Connection.new("flame.mongohq.com", 27044).db("notes")

But still got the error, after timeout:

$ ruby mongodbtest.rb 
/Library/Ruby/Gems/1.8/gems/mongo-1.0.8/lib/../lib/mongo/connection.rb:489:in
`connect': failed to connect to any given host:port (Mongo::ConnectionFailure)
from /Library/Ruby/Gems/1.8/gems/mongo-1.0.8/lib/../lib/mongo/connection.rb:137:in
`initialize'
from mongodbtest.rb:4:in `new'
from mongodbtest.rb:4

The hostname and port are according to mongoHQ documentation, so they must be right.

Thanks for the help in advance.

2nd Update:

I just tested the mongodb connection string using terminal:

mongo mongodb://flame.mongohq.com:27044/notes -u foo -p bar

Unfortunately this would get me an connection failed error, honestly, I don’t know why…

  • 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-05-18T12:40:37+00:00Added an answer on May 18, 2026 at 12:40 pm

    I use

    uri =  URI.parse(ENV['MONGOHQ_URL'])
    @mongo_connection = Mongo::Connection.from_uri( uri )
    @mongo_db = @mongo_connection.db(uri.path.gsub(/^\//, ''))
    @mongo_db.authenticate(uri.user, uri.password)
    

    You can look up your mongo url using the heroku config --long command

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

Sidebar

Related Questions

I am extremely new to Java (just started this weekend) and have a background
I started using GitHub this weekend for a new personal project (we also use
I'm hoping this just needs a new pair of eyes casting over it. I
I just launched my test website in Windows Azure this weekend with a single
I just started a new Android project, WeekendStudy to continue learning Android development and
Our networks guys installed this patch over the weekend to our single server sharepoint
This just started happening three weeks or so ago. The content of my website
This just saves time. Since I already have a web applciation. I can just
I fear this just may not be possible, but I'm trying to create a
So for some reason this just doesn't make sense to me. What Im trying

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.