Getting error when trying to connect to mongodb atlas

I get this error:
/rbd/pnpm-volume/a2c3c6a9-9676-4e7a-8ecb-647c7e1a95f1/node_modules/mongodb/lib/operations/add_user.js:16
this.options = options ?? {};

This is the code that I am using:
const { MongoClient, ServerApiVersion } = require(‘mongodb’);
const uri = “mongodb+srv://QuackDev:” + process.env.rocketerDatabase + “@rocketer.iolndfg.mongodb.net/?retryWrites=true&w=majority”;
// Create a MongoClient with a MongoClientOptions object to set the Stable API version
const client = new MongoClient(uri, {
serverApi: {
version: ServerApiVersion.v1,
strict: true,
deprecationErrors: true,
}
});
async function run() {
try {
// Connect the client to the server (optional starting in v4.7)
await client.connect();
// Send a ping to confirm a successful connection
await client.db(“admin”).command({ ping: 1 });
console.log(“Pinged your deployment. You successfully connected to MongoDB!”);
} finally {
// Ensures that the client will close when you finish/error
await client.close();
}
}
run().catch(console.dir);

Ah i read through similar posts on this problem. I upgraded my nodejs version to version 14 and this issue was resolved.

2 Likes

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.