Failing inserts with node-mongodb-native 1.3.9

Today after I upgraded the MongoDB connector for NodeJS to the latest version 1.3.9 I encountered strange results with our tests. The ones which use .insert() operations on collections suddenly started to fail because of timeouts.

Finally, after some good old caveman debugging I discovered that a callback passed to .insert() was not called anymore, even with increased timeout. I wanted to check via mongo shell whether the freeze happened before or after the actual DB operation but the shell just showed an error. Mongo’s logfile explained why: It had exited with a segmentation fault. Some web research suggested that this possibly could have to do with BSON and the native BSON parser, so I ended up with disabling the native parser which fixes the problem for the moment.

To connect to Mongo without the native parser one can use the connect() method of MongoClient:

  1. var MongoClient = require('mongodb').MongoClient;
  2. MongoClient.connect("mongodb://localhost:27017/database?",
  3.   { db: { native_parser: false } }, function(err, db) {
  4.     if (!err) {
  5.       // insert like hell  
  6.     }
  7.   }
  8. );

Up to know I’m not sure why the native parser is not working on my machine. Maybe there is something wrong with the build environment npm uses to compile the BSON module. However I don’t know yet how to fix that. If someone encountered the same problem and managed to fix it, please let me know.

Comments (2)

FunatikerJuni 11th, 2013 at 12:50

Do you know „databank“? A database abstraction layer for NodeJS that supports MongoDB and others:

jonasJuni 11th, 2013 at 16:43

I didn’t knew of it so far, but how would it solve the problem? The databank-mongodb driver also has node-mongodb-native in its dependencies ( although in an older version.

Leave a comment

Your comment