Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Raspberry Pi: MongoError: Server at localhost:27017 reports wire version 0, but this version of Node.js Driver requires at least 2 (MongoDB2.6)

i try to set up a MongoDB and get a connection to the Database with Node.js. I am currently working with a Raspberry Pi 2. And the MongoDB Version= 2.4.

If I try to execute this code:

var MongoClient = require('mongodb').MongoClient; 
var url = "mongodb://localhost:27017/mydb";
MongoClient.connect(url, function(err, db) {
  if (err) throw err;
  console.log("Database created!");
  db.close();
});

I am getting this error:
MongoError: Server at localhost:27017 reports wire version 0, but this version of Node.js Driver requires at least 2 (MongoDB2.6).

And the Database looks like this:
{ "_id" : ObjectId("5aa1719e551ea6f4212f71c2"), "numer" : 1 }
{ "_id" : ObjectId("5aa1805aa17e0c953e4ec284"), "numer" : 1, "name" : "test" }

Maybe it is the Version of the Pi. But there must be other opportunities to do it.
Thanks for your help :)

like image 579
Benjamin Haegenlaeuer Avatar asked Mar 08 '18 18:03

Benjamin Haegenlaeuer


2 Answers

This looks like a version compatibility issue between your node driver and your database. MongoDB 2.4 is rather old; recent versions of the node driver likely don't support versions earlier than MongoDB 2.6.

Trying updating to use a more recent version of MongoDB; MongoDB 2.4 is well past end-of-life.

like image 136
Adam Harrison Avatar answered Oct 25 '22 22:10

Adam Harrison


Thanks for all the answers.

I found a workaround with docker on the raspberry pi.

For that, I installed hypriot (docker optimized pi os) on the pi and then I started a MongoDB docker container.

For more information: https://blog.hypriot.com/getting-started-with-docker-on-your-arm-device/

like image 45
Benjamin Haegenlaeuer Avatar answered Oct 25 '22 21:10

Benjamin Haegenlaeuer