本文介绍了无法连接到mongolab,出现MongoError:验证失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我最近在mongoLab中创建了一个帐户.当我尝试使用以下语句连接到数据库时.

I have recently created an account in mongoLab.When I am trying to connect to the database using the below statement.

var mongoose = require('mongoose');
mongoose.connect('mongodb://mk:[email protected]:47742/mkdb');

我总是遇到以下错误

MongoError: auth failed
at Function.MongoError.create (/Users/a042292/Desktop/start/node_modules/mongoose/node_modules/mongodb/node_modules/mongodb-core/lib/error.js:31:11)
at /Users/a042292/Desktop/start/node_modules/mongoose/node_modules/mongodb/node_modules/mongodb-core/lib/topologies/server.js:793:66
at Callbacks.emit (/Users/a042292/Desktop/start/node_modules/mongoose/node_modules/mongodb/node_modules/mongodb-core/lib/topologies/server.js:94:3)
at null.messageHandler (/Users/a042292/Desktop/start/node_modules/mongoose/node_modules/mongodb/node_modules/mongodb-core/lib/topologies/server.js:235:23)
at Socket.<anonymous> (/Users/a042292/Desktop/start/node_modules/mongoose/node_modules/mongodb/node_modules/mongodb-core/lib/connection/connection.js:259:22)
at Socket.emit (events.js:107:17)
at readableAddChunk (_stream_readable.js:163:16)
at Socket.Readable.push (_stream_readable.js:126:10)
at TCP.onread (net.js:538:20)

推荐答案

请确保您使用的是数据库usernamepassword而不是Mlab的帐户usernamepassword.

Make sure you are using the database username and password not the account username and password from Mlab.

在MLab(以前为MongoLab)中,执行以下操作

In MLab, formerly MongoLab, do the following

  1. 导航到Users
  2. Add Database User
  3. 选择您的用户名和密码
  1. Navigate to Users
  2. Add Database User
  3. Choose your username and password

现在,您可以使用以下命令在Shell上进行测试 mongo ds061374.mlab.com:61374/yourdb -u <dbuser> -p <dbpassword>

Now you can test this on the shell with mongo ds061374.mlab.com:61374/yourdb -u <dbuser> -p <dbpassword>

这篇关于无法连接到mongolab,出现MongoError:验证失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-13 21:53