NodeJS and node-mongodb-native


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('',mongo.Connection.DEFAULT_PORT, {}), {});, db) {
    db.collection('things', function(err, collection) {
//          collection.insert(row);
        collection.find({}, null, function(err, cursor) {
            cursor.each(function(err, doc) {


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...


try to call after your insert to flush your row.

take a look at

"Currently Mongoose only supports manual flushing of data to the server."

This video can help you solving your question :)
By: admin