'MongoError: setName from ismaster does not match provided connection setName' when trying to connect to a MongoDB cluster using mongoose

Viewed 1711

I am student trying to build a restful API for a project. I am very new to this so please excuse me if it is an easy fix.

I am using "mongoose": "^5.3.4", and trying to connect to a cluster named '128project' in Mongo DB Atlas 3.6.8.

Here is the snippet I am using to connect:

mongoose.connect( uri ,{ useNewUrlParser: true }).catch(function (reason) {
    console.log('error ', reason);
});

The URI I am using is exactly what the Mongo Atlas DB provided.

I get this in the terminal:

error  { MongoError: setName from ismaster does not match provided connection setName [128project-shard-0] != [128]
    at ReplSetState.update (C:\Users\TAHP TAHP TAHP\Desktop\128test\node_modules\mongodb-core\lib\topologies\replset_state.js:403:14)
    at C:\Users\TAHP TAHP TAHP\Desktop\128test\node_modules\mongodb-core\lib\topologies\replset.js:809:45
    at applyAuthenticationContexts (C:\Users\TAHP TAHP TAHP\Desktop\128test\node_modules\mongodb-core\lib\topologies\replset.js:731:12)
    at Server.<anonymous> (C:\Users\TAHP TAHP TAHP\Desktop\128test\node_modules\mongodb-core\lib\topologies\replset.js:802:7)
    at Object.onceWrapper (events.js:315:30)
    at emitOne (events.js:116:13)
    at Server.emit (events.js:211:7)
    at C:\Users\TAHP TAHP TAHP\Desktop\128test\node_modules\mongodb-core\lib\topologies\server.js:508:16
    at C:\Users\TAHP TAHP TAHP\Desktop\128test\node_modules\mongodb-core\lib\connection\pool.js:532:18
    at _combinedTickCallback (internal/process/next_tick.js:132:7)
    at process._tickCallback (internal/process/next_tick.js:181:9) name: 'MongoError', [Symbol(mongoErrorContextSymbol)]: {} }

Any feedback is appreciated!

2 Answers

For the sake of completion - this happened to me as well when connecting to MongoDB 4.2 ReplicaSet. I removed the replicaSet=some_name part from the URI and it worked.

It's a known issue for some drivers, see this too.

What's the uri which you want to connect, it must be like this format

mongodb://username:password@10.0.0.298,10.0.1.299/db_name?replicaSet=replSetName
Related