1
votes
   const uri = 'mongodb+srv:<username>//:<passwod>@chatapp-qrps3.azure.mongodb.net/test?retryWrites=true&w=majority'

   const client = new MongoClient(uri, { useNewUrlParser: true, useUnifiedTopology: true })

   client.connect(err => {
       console.log(err)
       client.close();
   });

error seems like this

MongooseError [MongooseServerSelectionError]: connection to 40.79.242.22:27017 closed at new MongooseServerSelectionError (/Users/sherin/Desktop/sherinshaju/reactsocket/node_modules/mongoose/lib/error/serverSelection.js:22:11) at NativeConnection.Connection.openUri (/Users/sherin/Desktop/sherinshaju/reactsocket/node_modules/mongoose/lib/connection.js:823:32) at Mongoose.connect (/Users/sherin/Desktop/sherinshaju/reactsocket/node_modules/mongoose/lib/index.js:333:15) at Object. (/Users/sherin/Desktop/sherinshaju/reactsocket/app.js:28:4) at Module._compile (internal/modules/cjs/loader.js:1147:30) at Object.Module._extensions..js (internal/modules/cjs/loader.js:1167:10) at Module.load (internal/modules/cjs/loader.js:996:32) at Function.Module._load (internal/modules/cjs/loader.js:896:14) at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:71:12) at internal/main/run_main_module.js:17:47 { message: 'connection to 40.79.242.22:27017 closed', name: 'MongooseServerSelectionError', reason: TopologyDescription { type: 'ReplicaSetNoPrimary', setName: null, maxSetVersion: null, maxElectionId: null, servers: Map(3) { 'chatapp-shard-00-02-qrps3.azure.mongodb.net:27017' => [ServerDescription], 'chatapp-shard-00-00-qrps3.azure.mongodb.net:27017' => [ServerDescription], 'chatapp-shard-00-01-qrps3.azure.mongodb.net:27017' => [ServerDescription] }, stale: false, compatible: true, compatibilityError: null, logicalSessionTimeoutMinutes: null, heartbeatFrequencyMS: 10000, localThresholdMS: 15, commonWireVersion: null }, [Symbol(mongoErrorContextSymbol)]: {} }

1

1 Answers

2
votes

I think the form of the URI should be in the following manner:

const mongoURI = 'mongodb+srv://<username>:<password>[email protected]/test'

I think you have missed out the username in your URI.