Reputation: 2375
This is dependency on my program :
var express = require('express'),
app = express(),
cons = require('consolidate'),
MongoClient = require('mongodb').MongoClient,
mongodb = require('mongodb'),
Server = require('mongodb').Server;
var mongoclient = new MongoClient(new Server("localhost", 27017));
var db = mongoclient.db('prisync_mamy');
This query working fine in nodejs with mongo 2.6
db.collection('coll').insert_one(documen , function(err , records){
if (err) throw err;
});
but when upgrade mongo 2.6 to 3.x then it gives error :
MongoError: driver is incompatible with this server version at Object.toError (/home/ekodev/Documents/ComParice/node_modules/mongodb/lib/mongodb/utils.js:110:11) at __executeInsertCommand (/home/ekodev/Documents/ComParice/node_modules/mongodb/lib/mongodb/db.js:1829:27) at Db._executeInsertCommand (/home/ekodev/Documents/ComParice/node_modules/mongodb/lib/mongodb/db.js:1930:5) at insertAll (/home/ekodev/Documents/ComParice/node_modules/mongodb/lib/mongodb/collection/core.js:205:13) at Collection.insert (/home/ekodev/Documents/ComParice/node_modules/mongodb/lib/mongodb/collection/core.js:35:3) at app.get.pro_url (/home/ekodev/Documents/ComParice/app.js:72:47)
at callbacks (/home/ekodev/Documents/ComParice/node_modules/express/lib/router/index.js:164:37) at param (/home/ekodev/Documents/ComParice/node_modules/express/lib/router/index.js:138:11) at pass (/home/ekodev/Documents/ComParice/node_modules/express/lib/router/index.js:145:5) at Router._dispatch (/home/ekodev/Documents/ComParice/node_modules/express/lib/router/index.js:173:5)
Upvotes: 0
Views: 2273
Reputation: 3667
In my case npm install [email protected]
worked, or try npm install mongoose
with your specific mongoDB driver version.
Upvotes: 1
Reputation: 1126
open cmd and type the following command
npm install [email protected]
And then run replace your code with the following code
var express = require('express'),
app = express(),
MongoClient = require('mongodb').MongoClient,
mongodb = require('mongodb'),
Server = require('mongodb').Server;
var MongoClient = require('mongodb').MongoClient
, Server = require('mongodb').Server;
var mongoClient = new MongoClient(new Server('localhost', 27017));
mongoClient.open(function(err, mongoClient) {
var db1 = mongoClient.db("mydb");
console.log('it\'s working ');
mongoClient.close();
});
Upvotes: 1