Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

node.js and mongodb and traceback saying Driver requires at least 2(MongoDB2.6)

Installed the latest node js and npm where node is of version v7.8.0 and then using npmv4.2.0 I installed the package mongodb locally using npm install mongodb got version v3.0.5.

Now When I try to establish connection from node.js to mongodb server using this mongodb package, I got traceback.

Why the latest version of node is not compatible with latest version of other packages like mongodb and where I can find this compatible tables if there is any :^). Thanks for you help.

Code:

    var mongo = require('mongodb');
    var MongoClient = mongo.MongoClient;
    var DB_NAME = 'demodb';
    var url = "mongodb://localhost:27017/" + DB_NAME;

    MongoClient.connect(url, function(err, db) {
        if (err) {
            console.log('Error in creating DB ' + DB_NAME);
            throw err;
        }
        //var db = client.db(DB_NAME);
        console.log("Database " + DB_NAME + " created successfully!");
        db.close();
    });

Traceback

    Error in creating Database

    /home/manish/projects/practice/nodejs/node_modules/mongodb/lib/mongo_client.js:792
              throw err;
          ^
    MongoError: Server at localhost:27017 reports wire version 0, but this version of Node.js Driver requires at least 2 (MongoDB2.6).
    at /home/manish/projects/practice/nodejs/node_modules/mongodb-core/lib/topologies/server.js:377:39
    at /home/manish/projects/practice/nodejs/node_modules/mongodb-core/lib/connection/pool.js:541:18
    at _combinedTickCallback (internal/process/next_tick.js:73:7)
    at process._tickCallback (internal/process/next_tick.js:104:9)
like image 937
MaNKuR Avatar asked Oct 14 '25 05:10

MaNKuR


1 Answers

Adding my findings here to get rid of the problems. However, I won't mind(In-fact I'll appreciate instead) if anyone defers in the answer and suggest a better one.

Searched a bit and found a module mongodb-version-list to list all the versions supported for the current installed node v7.8.0 and npm v4.2.0 I guess.

["3.7.3","3.7.2","3.7.1","3.6.4-rc0","3.6.3","3.6.3-rc1","3.6.3-rc0","3.6.2","3.6.2-rc0","3.6.1","3.6.1-rc1","3.6.1-rc0","3.6.0",
    "3.6.0-rc8","3.6.0-rc7","3.6.0-rc6","3.6.0-rc5","3.6.0-rc4","3.6.0-rc3","3.6.0-rc2","3.6.0-rc1","3.6.0-rc0","3.5.13","3.5.12",
    "3.5.11","3.5.10","3.5.9","3.5.8","3.5.7","3.5.6","3.5.5","3.5.4","3.5.3","3.5.2","3.5.1","3.4.14","3.4.14-rc0","3.4.13","3.4.12",
    "3.4.12-rc0","3.4.11","3.4.11-rc0","3.4.10","3.4.10-rc0","3.4.9","3.4.9-rc0","3.4.8","3.4.8-rc1","3.4.8-rc0","3.4.7","3.4.7-rc0","3.4.6",
    "3.4.6-rc0","3.4.5","3.4.5-rc4","3.4.5-rc3","3.4.5-rc2","3.4.5-rc1","3.4.5-rc0","3.4.4","3.4.4-rc0","3.4.3","3.4.3-rc2","3.4.3-rc1","3.4.2",
    "3.4.2-rc0","3.4.1","3.4.1-rc0","3.4.0","3.4.0-rc5","3.4.0-rc4","3.4.0-rc3","3.4.0-rc2","3.4.0-rc1","3.4.0-rc0","3.3.15","3.3.14","3.3.13",
    "3.3.12","3.3.11","3.3.10","3.3.9","3.3.8","3.3.7","3.3.6","3.3.5","3.3.4","3.3.3","3.3.2","3.3.1","3.3.0","3.2.19","3.2.19-rc0","3.2.18",
    "3.2.18-rc0","3.2.17","3.2.17-rc0","3.2.16","3.2.16-rc0","3.2.15","3.2.15-rc0","3.2.14","3.2.14-rc1","3.2.14-rc0","3.2.13","3.2.13-rc0",
    "3.2.12","3.2.12-rc0","3.2.11","3.2.11-rc1","3.2.11-rc0","3.2.10","3.2.10-rc2","3.2.10-rc1","3.2.10-rc0","3.2.9","3.2.9-rc1","3.2.9-rc0",
    "3.2.8","3.2.8-rc1","3.2.8-rc0","3.2.7","3.2.7-rc1","3.2.7-rc0","3.2.6","3.2.6-rc0","3.2.5","3.2.5-rc1","3.2.5-rc0","3.2.4","3.2.4-rc0","3.2.3",
    "3.2.2","3.2.2-rc2","3.2.2-rc1","3.2.2-rc0","3.2.1","3.2.1-rc3","3.2.1-rc2","3.2.1-rc1","3.2.1-rc0","3.2.0","3.2.0-rc6","3.2.0-rc5","3.2.0-rc4",
    "3.2.0-rc3","3.2.0-rc2","3.2.0-rc1","3.2.0-rc0","3.1.9","3.1.8","3.1.7","3.1.6","3.1.5","3.1.4","3.1.3","3.1.2","3.1.1","3.1.0","3.0.15",
    "3.0.15-rc0","3.0.14","3.0.13","3.0.13-rc0","3.0.12","3.0.12-rc0","3.0.11","3.0.10","3.0.10-rc1","3.0.10-rc0","3.0.9","3.0.9-rc0","3.0.8",
    "3.0.8-rc0","3.0.7","3.0.7-rc0","3.0.6","3.0.6-rc2","3.0.6-rc1","3.0.6-rc0","3.0.5","3.0.5-rc2","3.0.5-rc1","3.0.5-rc0","3.0.4","3.0.4-rc0",
    "3.0.3","3.0.3-rc2","3.0.3-rc1","3.0.3-rc0","3.0.2","3.0.2-rc0","3.0.1","3.0.1-rc0","3.0.0","3.0.0-rc9","3.0.0-rc8","3.0.0-rc7","3.0.0-rc6",
    "3.0.0-rc11","3.0.0-rc10","2.8.0-rc5","2.8.0-rc4","2.8.0-rc3","2.8.0-rc2","2.8.0-rc1","2.8.0-rc0","2.7.8","2.7.7","2.7.6","2.7.5","2.7.4","2.7.3",
    "2.7.2","2.7.1","2.7.0","2.6.12","2.6.12-rc0","2.6.11","2.6.11-rc0","2.6.10","2.6.10-rc0","2.6.9","2.6.9-rc0","2.6.8","2.6.8-rc0","2.6.7","2.6.7-rc0",
    "2.6.6","2.6.6-rc0","2.6.5","2.6.5-rc4","2.6.5-rc3","2.6.5-rc2","2.6.5-rc1","2.6.5-rc0","2.6.4","2.6.4-rc1","2.6.3","2.6.2","2.6.2-rc1","2.6.2-rc0",
    "2.6.1","2.6.1-rc1","2.6.1-rc0","2.6.0","2.6.0-rc3","2.6.0-rc2","2.6.0-rc1","2.6.0-rc0","2.5.5","2.5.4","2.5.3","2.5.2","2.5.1","2.5.0","2.4.14",
    "2.4.14-rc0","2.4.13","2.4.13-rc0","2.4.12","2.4.12-rc0","2.4.11","2.4.11-rc0","2.4.10","2.4.10-rc0","2.4.9","2.4.9-rc0","2.4.8","2.4.7",
    "2.4.7-rc0","2.4.6","2.4.6-rc1","2.4.6-rc0","2.4.5","2.4.5-rc0","2.4.4","2.4.4-rc0","2.4.3","2.4.3-rc0","2.4.2","2.4.2-rc0","2.4.1","2.4.0",
    "2.4.0-rc3","2.4.0-rc2","2.4.0-rc1","2.4.0-rc0","2.3.2","2.3.1","2.3.0","2.2.7","2.2.7-rc0","2.2.6","2.2.6-rc0","2.2.5","2.2.5-rc0","2.2.4",
    "2.2.4-rc0","2.2.3","2.2.3-rc1","2.2.3-rc0","2.2.2","2.2.2-rc1","2.2.2-rc0","2.2.1","2.2.1-rc1","2.2.1-rc0"]

Now coming to the traceback I mentioned in the post I found its the mongodb database server version 2.4.14 that does not seems compatible with installed mongodb package i.e v3.0.5. So after googled a bit and degraded the mongodb package version to 2.2.16 and it works just fine.

like image 145
MaNKuR Avatar answered Oct 17 '25 17:10

MaNKuR