Adding a replica in MongoDB throws an error

mongodb replica set
mongodb remove replica set
mongodb 3 node replica set
mongodb add a replica
mongodb failover
failed with command replsetheartbeat requires authentication
mongodb replica set members
mongodb replica set connection refused

I'm trying to add a node to a replica set using rs.add("developer-ViratualBox:30103") and I'm getting the following error message:

{
"ok" : 0,
"errmsg" : "Quorum check failed because not enough voting nodes responded; required 2 but only the following 1 voting nodes responded: developer-VirtualBox:30101; the following nodes did not respond affirmatively: developer-ViratualBox:30103 failed with Failed attempt to connect to developer-ViratualBox:30103; couldn't initialize connection to host developer-ViratualBox, address is invalid",
"code" : 74
}

The node is already running and I'm connected to it using mongo shell. What could possibly be the problem?

The actual error is couldn't initialize connection to host developer-ViratualBox, address is invalid, Simply the primary node is not able to connect with secondery nodes. check connections, firewall, and check connection with mongo shell whether you can access that port or not.

replica set unable to add a node, I had create a primary node then I am trying to add a secondary node but it gives an error Adding a replica in MongoDB throws an error 2. When I Try to use java api to insert many data into Mongodb4.0 (replica set) it throws duplicate key errors. The amount of data is not too large, only about 300000 . & insert in 3-5 seconds . firstly I searched from the official document & website. it shows. Runs up to 256^3 per process (16777216)

The missing point is that the instance that I was trying to add did not have mongod instance started at the port defined. The given connection parameters hence were incorrect, and that caused the communication problem.

Troubleshoot Replica Sets, Secondary; Check the Size of the Oplog; Oplog Entry Timestamp Error. This section describes common strategies for troubleshooting replica set deployments​. A replica set can have a maximum of seven voting members. To add a member to a replica set that already has seven voting members, you must either add the member as a non-voting member or remove a vote from an existing member.

While starting secondary mongod process use --replSet option the try to run rs.add("localhost:27002") from primary mongod shell.

rs.stepDown(), The method is only valid against the primary and throws an error if run on a non-​primary member. The rs.stepDown() method has the following parameters:  This is almost certainly an issue with the underlying mongodb driver, because mongoose doesn't do anything with replica sets on its own. There were some issues with replica sets that were fixed in mongodb driver 2.2.11, will upgrade for mongoose 4.6.5 and see if that fixes it.

While creating rsconf file please enter <localhost:port> instead of <hostname:port>. And then reconfig(rsconf).

example :

rs0:PRIMARY>     
rsconf = {
             _id: "rs0",
             members: [
                 {
                     _id: 0,
                     host: "**localhost**:port for primary rs"
                 }]
         }

rs0:PRIMARY> rs.initiate(rsconf)
    {
        "info" : "try querying local.system.replset to see current configuration",
        "ok" : 0,
        "errmsg" : "already initialized",
        "code" : 23
    }

If you are getting above error then use the below command:

rs0:PRIMARY> rs.reconfig(rsconf)

Adding secondary node : rs.add("localhost:port for secondary rs")

Hope it will work.

Add Members to a Replica Set, Overview¶. This tutorial explains how to add an additional member to an existing replica set. For background on replication deployment patterns, see the Replica  When bound only to the localhost, these MongoDB 3.6 binaries can only accept connections from clients (including the mongo shell, other members in your deployment for replica sets and sharded clusters) that are running on the same machine. Remote clients cannot connect to the binaries bound only to localhost.

Another possible issue is that the machine that you are trying to add to the replica set is not configured to run with replication. Adding this entry to the mongod.conf on the machine that you're trying to add and restarting the service worked for me:

replication:
  replSetName: evoReplicaSet

Mongoose 4.6.2 produces error "MongoError: no primary found in , Simple connection to a MongoDB replica set. Works great Mongoose 4.6.2 produces error "MongoError: no primary found in replicaset" while 4.4.19 works just fine #4596 vkarpov15 added a commit that referenced this issue on Oct 21, 2016 /node_modules/mongodb/lib/mongo_client.js:225 throw err  For the following MongoDB versions, pv1 increases the likelihood of w:1 rollbacks compared to pv0 (no longer supported in MongoDB 4.0+) for replica sets with arbiters: MongoDB 3.4.1; MongoDB 3.4.0; MongoDB 3.2.11 or earlier; See Replica Set Protocol Version. See also: Add Members to a Replica Set; Add an Arbiter to Replica Set; Replace a Replica Set Member

MongoDB Node.JS Driver 1.4.9 documentation, mongodb:// is a required prefix to identify that this is a string in the standard The driver verifies that the name of the replica set it connects to matches this name. true: Sync to journal. false: the driver does not add j to the getlasterror function(​err, database) { if(err) throw err; db = database; // Start the application after the  Add a shard to the cluster using the sh.addShard() method, as shown in the examples below. Issue sh.addShard() separately for each shard. If the shard is a replica set, specify the name of the replica set and specify a member of the set. In production deployments, all shards should be replica sets.

MongoDB ReplicaSet on Docker Environment, TIL – Jest expect to throw error in an async call → I was playing around with MongoDB ReplicaSet yesterday in a Docker environment. is to connect to the primary server, initialize the replica set and insert initial data (seeding). However, I get an error saying that it couldn't locate mongo-secondary . Short version: Is there a way to add a new SECONDARY server to an existing production MongoDB replica set without downtime, and without temporarily disabling the "auth" and "keyfile" config setting

Mongoose v5.9.10: Connecting to MongoDB, Mongoose will not throw any errors by default if you use a model without connecting. Because this is a major change, they added the useNewUrlParser flag to allow If you're experiencing a similar error, connect to the replica set using the  This document describes the URI formats for defining connections between applications and MongoDB instances in the official MongoDB drivers. For a list of drivers and links to driver documentation, see drivers. You can specify the MongoDB connection string using either: the DNS Seedlist Connection Format. This section describes the standard

Comments
  • Did you resolved the issue?
  • yes. please see my answer
  • this is really helpful. btw I am setting mongo cluster on localhost. do you have a doc file for this? can you share it.
  • did you host one on localhost and one else where? I can't seem to get it to work.
  • @mirana no, all the instances were on localhost
  • Unfortunately no. The nodes were not on the same machine.
  • I get this error while connected to primary, trying to add secondary