Closed fegodev closed 1 year ago
When you set the overrideMethods option to all or add aggregate to its list you will see this error when running Mongo's .aggregate method with "$geoNear" in its first stage:
overrideMethods
all
aggregate
.aggregate
"$geoNear is only valid as the first stage in a pipeline."
During override the deleted filter is added to the top of the pipeline. It should have a fallback if $geoNear is in the first stage somewhere around here: https://github.com/dsanel/mongoose-delete/blob/313f434ae825c2de4869284ae24eb95cdef82ee1/index.js#L142
Remove aggregate from overrideMethods option and exclude deleted documents manually in your aggregation.
Or simply use aggregateWithDeleted, and add {deleted: false} to your $geoNear stage.
{deleted: false}
$geoNear
What's happening?
When you set the
overrideMethods
option toall
or addaggregate
to its list you will see this error when running Mongo's.aggregate
method with "$geoNear" in its first stage:"$geoNear is only valid as the first stage in a pipeline."
Why is this happening?
During override the deleted filter is added to the top of the pipeline. It should have a fallback if $geoNear is in the first stage somewhere around here: https://github.com/dsanel/mongoose-delete/blob/313f434ae825c2de4869284ae24eb95cdef82ee1/index.js#L142
Workaround?
Remove
aggregate
fromoverrideMethods
option and exclude deleted documents manually in your aggregation.