Search code examples
rmongodbdatabase-connectionmongolitelibmongoc

Error connecting to mongoDB using Mongolite


I'm having issues connecting to my MongoDB via Mongolite, and I'm not sure if it is an issue on my side, or if I need to use a different package to connect to the database. Please keep in mind that I cannot change the software being run by the MongoDB server, and I am a novice when it comes to all of this, so it could just be a silly error on my part.

I've run the following code:

m <- mongo(collection = "test", url="mongodb://22.92.59.149:27017")

As far as I can tell from the Mongolite tutorial (https://jeroen.github.io/mongolite/), this is the correct syntax to connect to the database, but I'm not 100% sure. Regardless, I get the following error:

Error: Server at 22.92.59.149:27017 reports wire version 2, 
but this version of libmongoc requires at least 3 (MongoDB 3.0)

From what I can tell, this means that mongolite won't work with my database. If that is the case, what other package should I try to use to connect, or if it is not the issue what am I doing wrong?

Thanks in advance!


Solution

  • As the message says, there is a mismatch between versions of the client and the server.

    More precisely, mongolite relies on a more general driver written in C, libmongoc, and it seems the version automatically installed by the install.packages("mongolite") statement is too recent towards the server's version.

    If you can't change anything server-side, maybe you could try to manually install an older version of libmongoc before installing mongolite, but I'm not confident about the compatibility with that R package afterwards.

    Maybe you can use RMongo, an older and archived package to interact with Mongo in R, but I'm afraid what you're going to develop won't be stable in further R versions.

    I'd rather recommend you to look at the problem server side.