Hello everyone,
I’m encountering an issue with my Node.js application when connecting to MongoDB version 6.8. The application works fine with MongoDB 5, but when I switch to MongoDB 6.8, I get the following error:
MongoRuntimeError: Unexpected null cursor id. A cursor creating command should have set this
Here’s the context: I have an async function that connects to the MongoDB database, retrieves a collection, and iterates over its documents using a cursor. Below is a simplified version of my code:
const { MongoClient } = require('mongodb');
async function connectDB() {
const url = "mongodb://127.0.0.1:27017/";
console.log("Connecting to database...");
const client = new MongoClient(url);
await client.connect();
console.log("Connected successfully to server");
const dbName = "mydb";
const db = client.db(dbName);
const collections = await db.listCollections().toArray();
console.log("Collections:");
collections.forEach((collection) => {
console.log(collection.name);
});
return { db, client };
}
The error happens when listing the collections. This error also happens when trying to fetch data.
Anyone can help me?