Collection() Create a new Collection instance (INTERNAL TYPE, do not instantiate directly)
正确代码如下:
var Db = require('mongodb').Db,
Server = require('mongodb').Server
var db = new Db('test01', new Server('localhost', 27017));
db.open(function(err, client) {
if (err) throw err;
console.log('connected to server');
var collection = db.collection('student');
collection.find(function(err, cursor) {
cursor.each(function(err, doc) {
if (doc) {
console.log(doc.uname);
}
});
});
});
根据文档,不能使用Collection直接构造Collection实例:
正确代码如下:
参考MongoDB官方文档