1

I'm new to this whole Nodejs, MongoDB, mongoose world. I'm just trying to follow some tutorials to get started and I keep getting this "Failed to load c++ bson extension, using pure JS version" error if I try and start any script with a reference to mongoose.

I've tried everything I can Google to fix it and nothing has worked including:

  • Reinstalling build-essentials
  • Reinstalling mongoDB
  • Downgrading nodejs to 0.10.22
  • deleting the node_modules dir
  • cleaing the npm cache

I'm at a loss. Can someone please help me out? I just want to get back to the learning!

I'm running both nodejs and MongoDB on a Ubuntu 13 server. This is my simple script.

var mongoose = require("mongoose");
mongoose.connect('mongodb://localhost/test');

var db = mongoose.connection;
db.on('error', console.error.bind(console, 'connection error:'));
db.once('open', function () {
    var UsersSchema = mongoose.Schema({
        name: String
    });
    var User = mongoose.model('User', UsersSchema);
    var user = new User({ name: "SomeName" })
    user.save();
});

Thank you!

  • It just means it either couldn't compile the native version or it wasn't available. It's falling back on a pure JS version. Is it crashing when you actually try to run your script? – WiredPrairie Apr 18 '14 at 19:27
  • http://stackoverflow.com/questions/21656420/failed-to-load-c-bson-extension – WiredPrairie Apr 18 '14 at 19:28

2 Answers2

1

If you are using ubuntu 14.04 it may be related to this issue :

https://github.com/TooTallNate/node-gyp/issues/426

there are two methods to solve this problem:

upgrade gyp to the lastest version I found the --no-parallel option in svn source:https://code.google.com/p/gyp/source/browse/trunk/pylib/gyp/init.py

hack the node_gyp If you don't want upgrade your gyp, you can just comment line 316 of/usr/local/lib/node_modules/npm/node_modules/node-gyp/lib/configure.js

 argv.push('-Dvisibility=default')
 argv.push('-Dnode_root_dir=' + nodeDir)
 argv.push('-Dmodule_root_dir=' + process.cwd())
 argv.push('--depth=.')
 //argv.push('--no-parallel')
Youen
  • 41
  • 3
0

I also faced similar problem in initial setup , fixed it by re installing build-essential package

sudo apt-get install build-essential

and then re install mongodb native driver also

npm install mongodb

The current version of node is v0.10.26. Try upgrading your node version also.

Sumeet Kumar Yadav
  • 11,912
  • 6
  • 43
  • 80