I’m trying to read an endless tailable cursor on a capped collection using NodeJS mongodb 6.15.0 against the mongo:latest docker image.
The code I use looks like:
const collection = await db.createCollection(collectionName, {
capped: true,
size: size,
max: max
})
const stream = collection.find({ _id: { $gt: 0 } }, {
tailable: true,
timeout: false,
awaitData: true
})
for await (const doc of stream) {
console.log(doc)
}
And I ran into two problems:
a) if the collection is empty, the cursor will immediatly end the iterator and it won’t be waiting for new records coming in. Only if a first record is found the iterator will wait for additional records to come in.
b) if I close the cursor with stream.close()
I would expect the iterator to cleanly end. Instead the driver throws MongoServerError: Executor error during getMore :: caused by :: operation was interrupted
Are there clean ways to solve this?
Kind regards,
Hans