无法连接到arduino yun上的mongo实验室

我不能在我的arduino yun上通过nodejs连接到mongodb或mongoose数据库。

Unable to connect to the mongoDB server. Error: { [MongoError: Authentication failed.] name: 'MongoError', message: 'Authentication failed.', ok: 0, code: 18, errmsg: 'Authentication failed.' } 

我得到这个错误。 该代码在我的台式电脑上正常工作。

 //lets require/import the mongodb native drivers. var mongodb = require('mongodb'); //We need to work with "MongoClient" interface in order to connect to a mongodb server. var MongoClient = mongodb.MongoClient; // Connection URL. This is where your mongodb server is running. var url = 'mongodb://*******:********@address:23118/arduino'; // Use connect method to connect to the Server MongoClient.connect(url, function (err, db) { if (err) { console.log('Unable to connect to the mongoDB server. Error:', err); } else { //HURRAY!! We are connected. :) console.log('Connection established to', url); // do some work here with the database. //Close connection db.close(); } }); 

我正在尝试连接到一个mongo实验室数据库。 我还没有尝试连接到任何其他数据库进行疑难解答。 这是因为我找不到一个免费的试用版,我不需要信用卡。

编辑:

我有一个Object Rocket实例,它在我的arduino yun上完美工作。 但是,它非常昂贵, 每月30美元(目前正在试用)。 而且我不需要速度或大量的数据。 所以如果有人可以弄清楚为什么它不能在mlab上工作,那将是很棒的。

过去我遇到过一些身份validation问题,我已经按照下面的步骤解决了这些问题:

1)确定mongo服务器和mongoose版本号

2)确定你的服务器使用什么authentication机制,并确保mongoose正在尝试使用你的服务器期望的身份authentication。 如果您使用的是旧版本,则某些validation机制可能不受支持,因此您需要升级。

3)确定用户的创build地点。 查看身份validation数据库并确保您的客户端使用此类数据库进行身份validation。 它可能与您存储数据的数据库不同。 事实上,它使用的是admin 。 如果是这样,看一下你可以添加到你的连接string的authSource选项。 更多信息在这里 。

除了上述所有内容,我build议您使用mongo客户端来validation您的凭据是否正确,并且可以连接到数据库。