mongodb - How to connect to mongo replica cluster in elixir -


i created mongo replica set trying connect elixir. created 3 mongo instance in replica set , gave hostnames in /etc/hosts thing working fine in mongo terminal , able connect mongo replica set. wrote code in node.js fetch data replica set using mongodb library , working fine(it means configuration in mongo server , local server fine as know ), when trying connect through elixir throwing error when connecting replica set.

i using following library connect it.

https://github.com/ankhers/mongodb 

as in library author has suggested use following configuration

{:ok, pid} = mongo.start_link(database: "test", seeds: "hostname1.net:27017", "hostname2.net:27017") 

which throwing syntax error.

** (syntaxerror) iex:6: syntax error before: "hostname2.net:27017" 

which obvious wrong.

when using configuration

worker(mongo, [[name: :mongo,database: "yatender", topology: "replica_set_no_primary",seeds: ["xxx.xxx.xxx.xxx:27017","xxx.xxx.xxx.xxx:27017","xxx.xxx.xxx.xxx:27017"] ,pool: dbconnection.poolboy]]) 

note:i have changed host address xxx don't confused it.

genserver #pid<0.1436.0> terminating ** (stop) exited in: genserver.call(#pid<0.1410.0>,  {:server_description, %{address: "xxx.xxx.xxx.xxx:27017", arbiters: [],  election_id: nil, error: nil, hosts: ["mongo.host1:27017",  "mongo.host2:27017", "mongo.host3:27017"],  last_update_time: -576460750248, last_write_date: %datetime{calendar:  calendar.iso, day: 26, hour: 6, microsecond: {0, 3}, minute: 47, month:  7, second: 23, std_offset: 0, time_zone: "etc/utc", utc_offset: 0,  year: 2017, zone_abbr: "utc"}, max_wire_version: 5, me:  "mongo.host3:27027", min_wire_version: 0, op_time: %{"t" =>  2, "ts" => #bson.timestamp<6446967716292067329>}, passives: [],  primary: "mongo.host2:27017", round_trip_time: 240, set_name:  "rs0", set_version: 4, tag_set: %{}, type: :rs_secondary}}, 30000) 

when use following configuration in worker

{:ok, pid} = mongo.start_link(database: "yatender", seeds: ["xxx.xxx.xxx.xxx:27017","xxx.xxx.xxx.xxx:27017","xxx.xxx.xxx.xxx:27017"]) 

this error comes

    [warn]  logger dropped 999 otp/sasl messages exceeded amount of 500 messages/second                                                                                     ** (exit #pid<0.1410.0>) exited in: genserver.call(#pid<0.1415.0>,  {:server_description, %{address: "xxx.xxx.xxx.xxx:27017", arbiters: [],  election_id: nil, error: nil, hosts: ["mongo.host1:27017",  "mongo.host2:27017", "mongo.host3:27027"],  last_update_time: -576460688733, last_write_date: %datetime{calendar:  calendar.iso, day: 26, hour: 6, microsecond: {0, 3}, minute: 58, month:  7, second: 13, std_offset: 0, time_zone: "etc/utc", utc_offset: 0,  year: 2017, zone_abbr: "utc"}, max_wire_version: 5, me:  "mongo.host1:27017", min_wire_version: 0, op_time: %{"t" => 2,  "ts" => #bson.timestamp<6446970508020809729>}, passives: [], primary:  "mongo.host2:27017", round_trip_time: 42, set_name: "rs0",  set_version: 4, tag_set: %{}, type: :rs_secondary}}, 30000) ** (exit) time out 

when directly connect standalone mongodb server not part of replica set works fine this.

# starts unpooled connection {:ok, conn} = mongo.start_link(database: "test",hostname: application.get_env(:api, :api_env)[:mongo_host])  # gets enumerable cursor results cursor = mongo.find(conn, "test-collection", %{})  cursor |> enum.to_list() |> io.inspect 

so stuck here , don't know missing. please guide me how can approach problem, wrong.

thanks in advance

after many hit & trials instead of server ip

{:ok, pid} = mongo.start_link(database: "yatender", seeds: ["xxx.xxx.xxx.xxx:27017","xxx.xxx.xxx.xxx:27017","xxx.xxx.xxx.xxx:27017"]) 

we have give name of hosts

{:ok, pid} = mongo.start_link(database: "yatender", seeds: ["mongo.host1:27017","mongo.host2:27017","mongo.host3:27017"]) 

we can use poolboy this.


Comments

Popular posts from this blog

html - How to custom Bootstrap grid height? -

javascript - pass values from mssql to views in node -

javascript - Understanding ExtJS Framework Syntax -