我是Mongo的新手,似乎在使某些基本功能正常工作时遇到问题。
带注释的代码如下。它的短期是db.getCollectionNames
没有定义,也db.foo.find()
还db.foos.find()
都弹了出来,即使是从实际执行工作中的代码上市FOO集合。
我的mongo安装缺少某些功能吗?
var MongoClient = require('mongodb').MongoClient;
MongoClient.connect('mongodb://localhost:27017/mongotest', function(err, db){
try {
db.collections(function(e, cols) {
cols.forEach(function(col) {
console.log(col.collectionName); //WORKS just fine
});
});
console.log(typeof db.getCollectionNames); //undefined
//db.foos.find(); //[TypeError: Cannot call method 'find' of undefined]
//db.foo.find(); //[TypeError: Cannot call method 'find' of undefined]
} catch (ex) {
console.log(ex);
} finally {
setTimeout(function(){ db.close(); }, 2000);
}
});
看起来您可能在看Mongo Shell文档或旧版本的node.js本机驱动程序API。
在当前的2.x版本的驱动程序中,getCollectionNames
已替换为listCollections
。
就db.foo.find()
语法而言,据我所知,本机驱动程序从未支持过该语法。相反,它将是:
db.collection('foo').find()
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句