NodeJS and node-mongodb-native
Posted
by w1nk
on Stack Overflow
See other posts from Stack Overflow
or by w1nk
Published on 2010-06-17T18:37:51Z
Indexed on
2010/06/17
18:43 UTC
Read the original article
Hit count: 591
Just getting started with node, and trying to get the mongo driver to work. I've got my connection set up, and oddly I can insert things just fine, however calling find on a collection produces craziness.
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));
});
});
});
});
If I uncomment the insert and comment out the find, it works a treat. The inverse unfortunately doesn't hold, I receive this error:
collection.find({}, null, function(err, cursor) {
^
TypeError: Cannot call method 'find' of null
I'm sure I'm doing something silly, but for the life of me I can't find it...
© Stack Overflow or respective owner