刚刚开始使用node,并尝试让mongo驱动程序工作.我已经建立了连接,奇怪的是我可以插入一些东西,但是在一个集合上调用find会产生疯狂.
var db = new mongo.Db('things', new mongo.Server('192.168.2.6',mongo.Connection.DEFAULT_PORT, {}), {});
db.open(function(err, db) {
db.collection('things', function(err, collection) {
// collection.insert(row);
collection.find({}, null, function(err, cursor) {
cursor.each(function(err, doc) {
sys.puts(sys.inspect(doc,true));
});
});
});
});
Run Code Online (Sandbox Code Playgroud)
如果我取消注释插入并注释掉查找,它将起作用.不幸的是,逆不成立,我收到此错误:
collection.find({}, null, function(err, cursor) {
^
TypeError: Cannot call method 'find' of null
Run Code Online (Sandbox Code Playgroud)
我确定我做的事情很傻,但对于我的生活,我找不到它......