2 / 4
Aug 2024

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?

25 days later

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

5 months later

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

2 months later

Even I’m facing the same issue after version 6.8.0. Getting error 'MongoRuntimeError: Unexpected null cursor id. A cursor creating command should have set this\n

This error is being thrown for

collection.aggregate().toArray()
collection.aggregate().next()

Can someone in the community please help us on this as we are stuck in upgrading the version since 2 weeks ?