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 8734481
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T09:50:57+00:00 2026-06-13T09:50:57+00:00

Ruby noob here. Any help with a little issue I’m having would be appreciated.

  • 0

Ruby noob here. Any help with a little issue I’m having would be appreciated.
I am trying to place an array into a connection string argument which is formatted as an array.

My array is as follows:

hosts = ["192.168.0.2:27017","192.168.0.3:27017"]

I need to pull the array apart and structure it like an array so that I can substitute all of the connections into the call at once. The number of hosts can vary so hence why its in an array.

hosts_mapped = hosts.map { |i| "'" + i.to_s + "'" }.join(",")

gives me “192.168.0.2:27017″,”192.168.0.3:27017” as a string I think… or this may have mapped it back to an array as I get an error which looks like the one below after trying to initiate a connection.

@conn = Mongo::ReplSetConnection.new([hosts_mapped], :refresh_mode => :sync, :refresh_interval => 10)

Exception `Mongo::ConnectionFailure' at gems/mongo-1.7.0/lib/mongo/util/pool_manager.rb:282 - Cannot connect to a replica set using seeds '192.168.0.2:27017
Mongo::ConnectionFailure: Cannot connect to a replica set using seeds '192.168.0.2:27017

As you can see it only seems to reference the first entry. I need to hold this array in a configuration file so this is the reason it does not go directly into the connection string above.
To me it seems I have mapped hosts_mapped back to an array, but if I puts hosts_mapped I get the string in the correct format.

"192.168.0.2:27017","192.168.0.3:27017"

A working connection string looks like:

@conn = Mongo::ReplSetConnection.new(["192.168.0.2:27017","192.168.0.3:27017"], :refresh_mode => :sync, :refresh_interval => 10)

Does anyone have any idea where I am going wrong here?

Full code to test:

#!/usr/bin/ruby -d 
require "mongo" 
hosts = ["192.168.0.2:27017","192.168.0.3:27017"] 
hosts_mapped = hosts.map {|i| "'" + i.to_s + "'" }.join(",") @conn =
Mongo::ReplSetConnection.new([hosts_mapped], :refresh_mode => :sync,:refresh_interval => 10)
  • 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-13T09:50:58+00:00Added an answer on June 13, 2026 at 9:50 am

    According to the docs Mongo::ReplSetConnection.new can take an array:

    Mongo::ReplSetConnection.new(['localhost:30000', 'localhost:30001'])
    

    Since you already have an array, you can just pass it as the first parameter:

    hosts = ["192.168.0.2:27017","192.168.0.3:27017"]
    Mongo::ReplSetConnection.new(hosts)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Ruby noob here! I have an array of structs that look like this Token
Ruby noob here. Trying to display a list of points as a polygon on
Noob question for Ruby on Rails- here's an example of my situation: If I
A bit of a noob here so apologies in advance. I am trying to
I am a Ruby noob and am simply trying to use the gets command
Kind of a ruby-noob active record query question: Magazine has_many :subscriptions User has_many :subscriptions
Ruby has a select method that takes an array and returns a subarray consisting
First of all you have to know I'm total Ruby noob :) I installed
I am a bit of a Ruby noob when it comes to the more
This is basically a very noob question about Ruby console (IRB), but I couldn't

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.