I recently updated my node version to the most recent stable one - v20.11.1
.
Also, I updated my mongodb node driver version on the package.json to ^6.5.0
.
Then I tried connecting to my DB using exactly the same code snippet on the mongo docs only using my URI:
const { MongoClient, ServerApiVersion } = require("mongodb");
// Replace the placeholder with your Atlas connection string
const uri = "<my connection string>";
// 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);
The connection did not succeed and it I got the following error:
MongoParseError: option connect is not supported
The full error:
/Users/user/Documents/mongoConnect/node_modules/mongodb/lib/connection_string.js:273
throw new error_1.MongoParseError(`${optionWord} ${Array.from(unsupportedOptions).join(', ')} ${isOrAre} not supported`);
^
MongoParseError: option connect is not supported
at parseOptions (/Users/user/Documents/mongoConnect/node_modules/mongodb/lib/connection_string.js:273:15)
at new MongoClient (/Users/user/Documents/mongoConnect/node_modules/mongodb/lib/mongo_client.js:52:63)
at Object.<anonymous> (/Users/user/Documents/mongoConnect/mong.js:7:16)
at Module._compile (node:internal/modules/cjs/loader:1376:14)
at Module._extensions..js (node:internal/modules/cjs/loader:1435:10)
at Module.load (node:internal/modules/cjs/loader:1207:32)
at Module._load (node:internal/modules/cjs/loader:1023:12)
at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:135:12)
at node:internal/main/run_main_module:28:49 {
[Symbol(errorLabels)]: Set(0) {}
}
I searched for this kind of error but couldn’t find any mention of it in regards to option connect
, only mostly in regards to useNewUrlParser
and useUnifiedTopology
.
Does anyone know why this happens and how do I fix it?
Thanks!