试图使用这篇文章连接到mlab
var mongo = require('mongodb');
var Server = mongo.Server;
var Db = mongo.Db;
var server = new Server('ds1234.mongolab.com', 12345, {auto_reconnect : true});
var db = new Db('db-name', server);
db.open(function(err, client) {
client.authenticate('username', 'password', function(err, success) {
// Do Something ...
});
});但也有错误:
连接ETIMEDOUT 40.78.24.54:12345
而且客户端是未定义的,所以它不能读取我需要连接到mlab并创建一些集合的客户端的属性“身份验证”,我怎么做呢?
发布于 2016-03-18 23:10:01
您已经从教程中复制了字符串"ds1234.mongolab.com“。但是你不能连接到那个地址,因为它不属于你。您需要在MongoLab和听从他们的指示上建立一个连接帐户。
发布于 2017-04-04 19:27:13
//install mongodb: npm install mongodb --save
var mongodb = require("mongodb");
var db;
// Connect to the database before starting the application server.
//Create User on Mlab and replace the URL
mongodb.MongoClient.connect("URL", function (err, database) {
if (err) {
console.log(err);
process.exit(1);
}
db = database;
console.log("Database connection ready");https://stackoverflow.com/questions/36085741
复制相似问题