在我的本地机器上,我以这种方式连接到 mongoDb“tasksdb”数据库:
var server = new Server('localhost', 27017, {auto_reconnect: true, });
db = new Db('tasksdb', server);
db.open(function(err, db) {
if(!err) {
console.log("Connected to 'tasksdb' database");
db.collection('tasks', {safe:true}, function(err, collection) {
if (err) {
console.log("The 'tasks' collection doesn't exist. Creating it with sample data...");
populateDB();
}
});
}
});
如何强制它在heroku上工作?我试过了:
var server = new Server(process.env.MONGOLAB_URI, process.env.PORT, {auto_reconnect: true, });
db = new Db('heroku_mydatabase', server);
但它不起作用。在网络中的每个示例中,人们都使用“连接”,但我想这样做。可能吗 ?