DEV Community

Emmanuel Osuolale
Emmanuel Osuolale

Posted on

How to fix MongoCompatibility Error when connecting to Azure Cosmos DB

Introduction

Last week I was trying to connect my Nodejs Application with Cosmos DB, I had already been using mongo DB and I saw that Azure had Mongo DB API connector for Cosmos DB and i decided to use this because I love Azure.
I was able to create it using the azure portal.
Next was to connect this on my node JS web app.

Creating the first connection

I googled how to do this and came across some repository on microsoft sample on how to do this and I tried to follow how they created the connection, it was like this

const mongoUri = `mongodb://${env.accountName}:${env.key}@${env.accountName}
.documents.azure.com:${env.port}/
${env.databaseName}
?ssl=true`;
Enter fullscreen mode Exit fullscreen mode

I went to my azure portal, clicked on setting then opened connection string and copied all the details requested from me only to see this in the terminal when i ran this.

error: MongoCompatibilityError: Server at XXXXX- 
 XXXX.documents.azure.com:10255 reports maximum   
wire version 2, but this version of the Node.js Driver  
  requires at least 6 (MongoDB 3.6)
Enter fullscreen mode Exit fullscreen mode

Troubleshooting

I googled and google and did not find a solution to this it was like this error did not exist anywhere.

Solution

My solution to this was to change the code for mongoUri to exactly what is in azure microsoft primary connection string.

Thought i would share this for someone who might encounter this challenge when connecting their Azure Cosmos DB API for MongoDB.

Thank you for reading this.

Top comments (0)