Ошибка MongoDB при подключении 'MongoServerSelectionError',

   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();
   });

ошибка кажется такой

MongooseError [MongooseServerSelectionError]: подключение к 40.79.242.22:27017 закрыто в новом MongooseServerSelectionError (/Users/sherin/Desktop/sherinshaju/reactsocket/node_modules/mongoose/lib/error/serverSelection.js:22:11) atConnection.Upenction.js:22:11) (/Users/sherin/Desktop/sherinshaju/reactsocket/node_modules/mongoose/lib/connection.js:823:32) в Mongoose.connect (/ Users / sherin / Desktop / sherinshaju / reactsocket / node_modules / mongoose / lib / index. js: 333: 15) в Object. (/Users/sherin/Desktop/sherinshaju/reactsocket/app.js:28:4) в Module._compile (internal / modules / cjs / loader.js: 1147: 30) в Object.Module._extensions..js (internal /modules/cjs/loader.js:1167:10) в Module.load (internal / modules / cjs / loader.js: 996: 32) в Function.Module._load (internal / modules / cjs / loader.js: 896 : 14) в Function.executeUserEntryPoint [как runMain] (internal / modules / run_main.js: 71: 12) в internal / main / run_main_module.js: 17: 47 {сообщение: 'соединение с 40.79.242.22:27017 закрыто', имя: 'MongooseServerSelectionError', причина: TopologyDescription {тип: 'ReplicaSetNoPrimary', setName: null, maxSetVersion: null, maxElectionId: null, серверы: 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]}, устаревший: false, совместимый: true, compatibilityError: null, logicalSessionTimeoutMinutes: null, heartbeatFrequencyMS: 10000, localThresholdMS: 15, commonWireVersion: null}, [Symbol (mongoErrorContextSymbol)]: {}}


person Sherin Shaju Athickal    schedule 25.03.2020    source источник


Ответы (1)


Я думаю, что форма URI должна быть следующей:

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

Я думаю, вы пропустили имя пользователя в своем URI.

person Y SAHITH    schedule 25.03.2020
comment
это не работает, я просто использую бесплатный сервер Mango db .. но я не могу подключиться к нему - person Sherin Shaju Athickal; 25.03.2020
comment
я просто забыл добавить имя пользователя в этом извините - person Sherin Shaju Athickal; 25.03.2020
comment
Пожалуйста, не стесняйтесь принять мой ответ, если он помог решить вашу проблему. - person Y SAHITH; 25.03.2020