Sunday, May 19, 2024
 Popular · Latest · Hot · Upcoming
34
rated 0 times [  38] [ 4]  / answers: 1 / hits: 6886  / 10 Years ago, wed, october 29, 2014, 12:00:00

I've been trying to make a simple site with Node.js, Express.js, and MongoDB. I'm new to these technologies and have been having problem set up the database
Here is snippet of code in my index.js file:



var http = require('http'),
express = require('express'),
path = require('path'),
MongoClient = require('mongodb').MongoClient,
Server = require('mongodb').Server,
CollectionDriver = require('./collectionDriver').CollectionDriver;

var app = express();
app.set('port', process.env.PORT || 3000);
app.set('views', path.join(__dirname, 'views'));
app.set('view engine', 'jade');

var mongoHost = 'localHost';
var mongoPort = 27017;
var collectionDriver;

var mongoClient = new MongoClient(new Server(mongoHost, mongoPort));
mongoClient.open(function(err, mongoClient) {
if (!mongoClient) {
console.error(Error! Exiting... Must start MongoDB first);
process.exit(1);
}
var db = mongoClient.db(MyDatabase);
collectionDriver = new CollectionDriver(db);
});


After I try to run node index.js in terminal, it says the following:



js-bson: Failed to load c++ bson extension, using pure JS version

/Users/username/dev/ga-final/index.js:31
mongoClient.open(function(err, mongoClient) { //C
^
TypeError: Object #<MongoClient> has no method 'open'
at Object.<anonymous> (/Users/username/dev/ga-final/index.js:31:13)
at Module._compile (module.js:456:26)
at Object.Module._extensions..js (module.js:474:10)
at Module.load (module.js:356:32)
at Function.Module._load (module.js:312:12)
at Function.Module.runMain (module.js:497:10)
at startup (node.js:119:16)
at node.js:906:3


What is wrong? Why can't I call open? Can you help me fix this? thanks!


More From » node.js

 Answers
8

This is happening may be because you are using new version of mongodb it is working fine after I use mongodb driver version 1.4.



npm install [email protected]

[#41620] Tuesday, October 28, 2014, 10 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
eanskylerg

Total Points: 524
Total Questions: 107
Total Answers: 100

Location: Colombia
Member since Mon, May 2, 2022
2 Years ago
;