Giter Site home page Giter Site logo

Comments (2)

sge-babrams avatar sge-babrams commented on May 29, 2024

@sandeshsoni I think this is probably a ruby config issue. How are you trying to connect to mongo in your app? if you are using the mongo gem you need to have it connect with a replicaset only when its mongo is configured to be one otherwise you need to use a different class. I do this with something like this in my initializer (forgive any typos I quickly grabbed and scrubbed some of our internal libs for here):

def init_mongo_with_retry(max_retries)
  retries=0
  require 'yaml'
mongo_config = YAML.load_file('<PATH_TO_SOME_YML_CONFIG>')[ENV[RACK_ENV]]['mongo']
  begin
    # if we have secure_config['mongo']['rs'] we connect with the mongo
    # replicaset client/class otherwise use basic
    if mongo_config['rs']
      $MONGO_CONN = Mongo::MongoReplicaSetClient.new(
        ["#{mongo_config['host']}:#{mongo_config['port']}"],
        :read => mongo_config['read'].to_sym,
        :name => mongo_config['rs'],
        :pool_size => mongo_config['pool_size'],
        :connect_timeout => mongo_config['conn_timeout'],
        :op_timeout => mongo_config['op_timeout']
      )
    else
      $MONGO_CONN = Mongo::MongoClient.new(mongo_config['host'], mongo_config['port'])
    end
    $MONGO = $MONGO_CONN.db(mongo_config['database'])
  rescue Mongo::ConnectionFailure => ex
    retries += 1
    STDERR.puts "Time: #{Time.now}, Mongo failed to connect to: #{$MONGO_CONN.seeds}, attempts: #{retries} "
    # here you can get ex.message
    raise ex if retries > max_retries
    retry
  end
end

init_mongo_with_retry(max_retries=60)

from mongo.

yosifkit avatar yosifkit commented on May 29, 2024

Seems this is not a mongo image problem, but a ruby configuration issue. Feel free to ping if there is a problem with the mongo image.

from mongo.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.