0
votes

I have a node.js server that tries to connect to mongodb (working with mongoose):

mongoose.connect('mongodb://127.0.0.1:27017/ordry', {useNewUrlParser: true, useFindAndModify: false, useCreateIndex: true}).then(result =>{ // 127.0.0.1:27017
    console.log("Successfully connected to db!");
}).catch(error =>{
    console.log("Error connecting to the database!")
})

Although mongodb is up and running, the connection fails.

I get the following logs:

Thu Jul 18 13:24:50.124 [initandlisten] options: { dbpath: "/home/pi/mongodb/" }

Thu Jul 18 13:24:50.166 [initandlisten] waiting for connections on port 27017

Thu Jul 18 13:24:50.166 [websvr] admin web console waiting for connections on port 28017

Thu Jul 18 13:25:45.647 [initandlisten] connection accepted from 127.0.0.1:50188 1 (1 connection now open)

Thu Jul 18 13:25:45.742 [conn1] end connection 127.0.0.1:50188 (0 connections now open)

EDIT Logs from Node.js:

[nodemon] starting `node ./server/server.js`
{ MongoNetworkError: failed to connect to server [127.0.0.1:27017] on first connect [MongoError: Server at 127.0.0.1:27017 reports maximum wire version 0, but this version of the Node.js Driver requires at least 2 (MongoDB 2.6)]
    at Pool.<anonymous> (/home/pi/Desktop/Ordry API/node_modules/mongodb-core/lib/topologies/server.js:431:11)
    at Pool.emit (events.js:198:13)
    at connect (/home/pi/Desktop/Ordry API/node_modules/mongodb-core/lib/connection/pool.js:557:14)
    at callback (/home/pi/Desktop/Ordry API/node_modules/mongodb-core/lib/connection/connect.js:109:5)
    at runCommand (/home/pi/Desktop/Ordry API/node_modules/mongodb-core/lib/connection/connect.js:140:7)
    at Connection.messageHandler (/home/pi/Desktop/Ordry API/node_modules/mongodb-core/lib/connection/connect.js:334:5)
    at Connection.emit (events.js:198:13)
    at processMessage (/home/pi/Desktop/Ordry API/node_modules/mongodb-core/lib/connection/connection.js:364:10)
    at Socket.<anonymous> (/home/pi/Desktop/Ordry API/node_modules/mongodb-core/lib/connection/connection.js:533:15)
    at Socket.emit (events.js:198:13)
    at addChunk (_stream_readable.js:288:12)
    at readableAddChunk (_stream_readable.js:269:11)
    at Socket.Readable.push (_stream_readable.js:224:10)
    at TCP.onStreamRead [as onread] (internal/stream_base_commons.js:94:17)
  name: 'MongoNetworkError',
  errorLabels: [ 'TransientTransactionError' ],
  [Symbol(mongoErrorContextSymbol)]: {} }

Conclusion

I am a bit unsure why it is not working here - especially as everything worked fine on windows.

I am using Raspbian on my Raspberry Pi 3b+.

Any help would be appreciated.

2
Why don't you log the error? console.log("Error connecting to the database!", error); It's a good practice to get more information.Eduardo Yáñez Parareda
@EduardoYáñezParareda please take a look at my updated question.linus_hologram

2 Answers

0
votes

usually this happens because you didn't start mongod process before you try starting mongo shell.

1) Delete mongod.lock file from C:\Program Files\MongoDB\Server\4.0\data

2) Start mongod server

In another terminal - start mongo shell

1) mongo

0
votes

The error message you get:

reports maximum wire version 0, but this version of the Node.js Driver requires at least 2 (MongoDB 2.6)

Is warning you to upgrade your MongoDB version to 2.6 at least, because it's not supported by the drivers used by the wire library which MongoDB depends on.

It seems that the version of MongoDB (2.4) provided by Raspbian is not supported anymore, so the best way to run a MongoDB server os a Raspberry Pi is to install another Linux distribution like Ubuntu or Arch Linux.