Closed adamreisnz closed 3 years ago
The docs are outdated, we removed the need to use exec()
for aggregation cursors in 6.0 with #10410. Will update the docs :+1:
Sweet as, is it still required/advisable to use .exec()
after regular querying, e.g. find
, findOne
, updateOne
, etc?
@adamreisnz using exec()
after querying is not required (unless you're using cls-hooked or similar libs), but advisable for cleaner stack traces.
It seems the changes between mongoose 5 and mongoose 6 caused your problem. In mongoose 5 aggregate.cursor return this
(the aggregate object), not the promise, and you have toexec()
to get the promise. In mongoose 6 aggregate.cursor()
return AggregateCursor
just like QueryCursor
( query.cursor() return QueryCursor in mongoose 5 )
@adamreisnz
Do you want to request a feature or report a bug? Bug, or outdated documentation
What is the current behavior? Referring to: https://mongoosejs.com/docs/api/aggregate.html#aggregate_Aggregate-cursor The example states:
However, our code yields:
Removing the
exec
part returns a cursor as expected.If the current behavior is a bug, please provide the steps to reproduce. See above
What is the expected behavior? For
exec
to work, or docs to be updated to no longer require this.What are the versions of Node.js, Mongoose and MongoDB you are using? Note that "latest" is not a version. Mongoose 6.0.7