我正在尝试将集群连接到Node.js应用程序,而我得到的只是一个authentication fail
错误。我已经尝试修复了一段时间,现在我真的很沮丧。
这是我的代码的样子:
const db = require('./config/keys').mongoURI;
mongoose
.connect(db, { useNewUrlParser: true })
.then(() => console.log('MongoDB Connected'))
.catch(err => console.log(err));
mongoURI看起来像这样:
mongodb+srv://namehere:<passwordhere>@cluster0-bhve1.mongodb.net/test?retryWrites=true
我不断收到此错误:
{ MongoError: authentication fail
at C:\Users\AyaLe\Desktop\nodes\node_modules\mongodb-core\lib\topologies\replset.js:1458:15
at C:\Users\AyaLe\Desktop\nodes\node_modules\mongodb-core\lib\connection\pool.js:869:7
at C:\Users\AyaLe\Desktop\nodes\node_modules\mongodb-core\lib\connection\pool.js:845:20
at finish (C:\Users\AyaLe\Desktop\nodes\node_modules\mongodb-core\lib\auth\scram.js:233:16)
at handleEnd (C:\Users\AyaLe\Desktop\nodes\node_modules\mongodb-core\lib\auth\scram.js:243:7)
at C:\Users\AyaLe\Desktop\nodes\node_modules\mongodb-core\lib\auth\scram.js:352:15
at C:\Users\AyaLe\Desktop\nodes\node_modules\mongodb-core\lib\connection\pool.js:532:18
at process._tickCallback (internal/process/next_tick.js:61:11)
errors:
[ { name: 'cluster0-shard-00-00-bhve1.mongodb.net:27017',
err: [MongoError] },
{ name: 'cluster0-shard-00-02-bhve1.mongodb.net:27017',
err: [MongoError] },
{ name: 'cluster0-shard-00-01-bhve1.mongodb.net:27017',
err: [MongoError] } ],
name: 'MongoError',
[Symbol(mongoErrorContextSymbol)]: {} }