I'm encountering an issue with connecting to MongoDB. The error message I'm receiving is:
| options.includeResultMetadata ??= false;
20:46:01 0|app | ^^^
20:46:01 0|app | SyntaxError: Unexpected token '??='
The Node version I'm using for the project is: node -v => v20.7.0
MongoDB version: mongod --version => db version v6.0.8
Here's my package.json file:
"dependencies": {
"compression": "^1.7.4",
"cors": "^2.8.5",
"express": "^4.18.2",
"helmet": "^7.0.0",
"http-status": "^1.7.0",
"mongodb": "^6.1.0",
"xss-clean": "^0.1.4"
}
}
Can anyone help me figure out what I might be missing?
And here's a snippet of my code:
const { MongoClient } = require('mongodb');
const uri = 'mongodb://localhost/testDatabase';
const client = new MongoClient(uri, {
useNewUrlParser: true,
useUnifiedTopology: true,
});
async function connectToDatabase() {
try {
await client.connect();
console.log('Connected to the MongoDB database');
} catch (err) {
console.error('Error connecting to the MongoDB database:', err);
}
}
module.exports = {
connectToDatabase,
getDatabase: () => client.db(),
};