Need Help with MongoRuntimeError: Unexpected Null Cursor ID in Node.js (MongoDB 6.8 Issue)

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?

I also had the same issue (with 6.8.0).
I installed the 6.5.0 mongodb version and now it works for me

1 Like

Were you able to update the dependency? Im having the same error still to this day