我正在尝试将 MongoDB 驱动程序用于 node.js 并获取集合列表。我认为这是获取数据的良好第一步。
我已经有一个通过 ruby 成功添加的集合和数据。根据文档,我的代码应该可以工作。
(function() {
var client, db, listAllData, server;
db = require('mongodb').Db;
server = require('mongodb').Server;
client = new db('images', new server('something.mongolab.com', 111111, {
username: 'username',
password: 'password'
}));
client.open(function(err, the_client) {
the_client.collectionNames(function(err, colls) {
console.log(colls);
});
});
}).call(this);
我觉得我必须缺少一些基本的东西。