Since version 3.6 MongoDB requires the use of cursor
or explain
in aggregate
queries. It's a breaking change so I have to modify my earlier code.
But when I add cursor
or explain
to my query, the request simply enters an endless loop and MongoDB never responds. It doesn't even seem to time out.
This simple aggregation just hangs the code and never responds:
db.collection('users').aggregate([{ $match: { username: 'admin' }}],
{ cursor: {} },
(err, docs) => {
console.log('Aggregation completed.');
});
I can replace { cursor: {} }
with { explain: true }
and the result is the same. It works perfectly under older MongoDB versions without this one parameter.
Without cursor
or explain
I get this error message:
The 'cursor' option is required, except for aggregate with the explain argument
I'm not the only one who ran into this: https://github.com/nosqlclient/nosqlclient/issues/419