Итак, я включил аутентификацию в MongoDB. Я создал пользователя в базе данных «admin» с именем пользователя «test» и паролем «password». Пользователь имеет роль «dbAdmin» для базы данных «testdb».
Я подключаюсь, используя mon goose. Вот mon go URI mongodb: // test@127.0.0.1: 27017 / testdb? AuthSource = admin.
Первое соединение отклонено mon go и оно подключается со второй попытки. Может кто-нибудь помочь мне понять, почему он не подключается в одну попытку? Моя база данных и служба узлов находятся на локальном хосте.
Вот журналы
[2020-04-28T06:01:37.489] [DEBUG] => Trying to connect to mongodb://test@127.0.0.1:27017/testdb?authSource=admin
(node:74504) DeprecationWarning: current Server Discovery and Monitoring engine is deprecated, and will be removed in a future version. To use the new Server Discover and Monitoring engine, pass option { useUnifiedTopology: true } to the MongoClient constructor.
[2020-04-28T06:01:38.063] [INFO] => Server running at: http://0.0.0.0:6001
[2020-04-28T06:01:38.077] [INFO] => Successfully connected to Redis at 127.0.0.1:6379
[2020-04-28T06:01:38.103] [FATAL] => { MongoNetworkError: failed to connect to server [127.0.0.1:27017] on first connect [MongoError: Authentication failed.]
at Pool.<anonymous> (/Users/applicationdeveloper/Sarthak/Projects/Test/node_modules/mongodb/lib/core/topologies/server.js:433:11)
at Pool.emit (events.js:198:13)
at Pool.EventEmitter.emit (domain.js:448:20)
at createConnection (/Users/applicationdeveloper/Sarthak/Projects/Test/node_modules/mongodb/lib/core/connection/pool.js:577:14)
at connect (/Users/applicationdeveloper/Sarthak/Projects/Test/node_modules/mongodb/lib/core/connection/pool.js:1007:11)
at callback (/Users/applicationdeveloper/Sarthak/Projects/Test/node_modules/mongodb/lib/core/connection/connect.js:93:5)
at provider.auth.err (/Users/applicationdeveloper/Sarthak/Projects/Test/node_modules/mongodb/lib/core/connection/connect.js:367:21)
at _authenticateSingleConnection (/Users/applicationdeveloper/Sarthak/Projects/Test/node_modules/mongodb/lib/core/auth/auth_provider.js:66:11)
at sendAuthCommand (/Users/applicationdeveloper/Sarthak/Projects/Test/node_modules/mongodb/lib/core/auth/scram.js:193:16)
at _callback (/Users/applicationdeveloper/Sarthak/Projects/Test/node_modules/mongodb/lib/core/connection/connect.js:320:5)
at Connection.messageHandler (/Users/applicationdeveloper/Sarthak/Projects/Test/node_modules/mongodb/lib/core/connection/connect.js:349:5)
at Connection.emit (events.js:198:13)
at Connection.EventEmitter.emit (domain.js:448:20)
at processMessage (/Users/applicationdeveloper/Sarthak/Projects/Test/node_modules/mongodb/lib/core/connection/connection.js:384:10)
at Socket.<anonymous> (/Users/applicationdeveloper/Sarthak/Projects/Test/node_modules/mongodb/lib/core/connection/connection.js:553:15)
at Socket.emit (events.js:198:13)
name: 'MongoNetworkError',
[Symbol(mongoErrorContextSymbol)]: {} }
[2020-04-28T06:01:38.106] [FATAL] => An unhandled exception has occurred
[2020-04-28T06:01:38.395] [INFO] => Successfully connected to MongoDB at 127.0.0.1:27017