Skip to content

Commit

Permalink
Better MongoDB cluster connection defaults
Browse files Browse the repository at this point in the history
  • Loading branch information
gousiosg committed Dec 20, 2019
1 parent 42eca40 commit 020e681
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 10 deletions.
2 changes: 1 addition & 1 deletion .ruby-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2.5.1
2.5
27 changes: 18 additions & 9 deletions lib/ghtorrent/adapters/mongo_persister.rb
Original file line number Diff line number Diff line change
Expand Up @@ -108,13 +108,13 @@ def mongo
host = config(:mongo_host)
port = config(:mongo_port)
db = config(:mongo_db)

replicas = config(:mongo_replicas)
replicas = if replicas.nil? then
''
else
',' + replicas.strip.gsub(' ', ',')
end

hosts = if replicas.nil? then
["#{host}:#{port}"]
else
["#{host}:#{port}"] + replicas.strip.split(/ /)
end

ssl = case config(:mongo_ssl)
when 'true', 'True', 't', true
Expand All @@ -123,13 +123,22 @@ def mongo
false
end


Mongo::Logger.logger.level = Logger::WARN
@mongo = Mongo::Client.new(["#{host}:#{port}"],
@mongo = Mongo::Client.new(hosts,
:database => db,
:password => passwd,
:user => uname,
:auth_source => 'admin')
:auth_source => 'admin',
:read => {
:mode => :secondary_preferred
},
:retry_reads => true,
:retry_writes => true,
:write_concern => {
:w => "majority",
:j => true
}
)

dbs = @mongo.list_databases
if dbs.find { |x| x['name'] == db }.nil?
Expand Down

0 comments on commit 020e681

Please sign in to comment.