dsanel / mongoose-delete

Mongoose Soft Delete Plugin
MIT License
346 stars 101 forks source link

version 0.5.2 is breaking $geoNear aggregation #79

Closed svengau closed 3 years ago

svengau commented 4 years ago

Hi, I have the following error with version 0.5.2 when using geo localised queries:

MongoError: $geoNear is only valid as the first stage in a pipeline.

Indeed, the first item in the aggregate query is now "{ $match: { deleted: { '$ne': true } } }" rather than $geoNear.

As a workaround, I've overridden the overrideMethods option.

waikuen2010 commented 4 years ago

Same issue here, I think 0.5.2 should not be a patch update. The minor version number should be pump up as it introduces breaking change / behavior change to project using overrideMethods: true/'all'.

taina0407 commented 3 years ago

@dsanel any update on this ?

dsanel commented 3 years ago

@svengau do you still have this problem. If you can share your solution with us or make PR it will be super?

svengau commented 3 years ago

@dsanel, sorry, I don't work on this project and the related customer anymore. So I won't be able to reproduce easily.

simplenotezy commented 2 years ago

@dsanel I have this issue. It happens when you use $geoNear, e.g. like so:

await this.userModel.aggregate([{
    $geoNear: {
        near: userModel.location,
        distanceField: 'distance',
        maxDistance: userModel.maxSuggestionDistance ?? Number.MAX_VALUE,
        key: 'location',
        query: {}, // some random query
    },
}])

My current workaround is to simply disable soft deletes override of aggregate methods.

As an alternative workaround, it would be cool, if you could disable the softdelete for a single query, instead of for all methods. For instance:

await this.userModel.disableSoftDeletes.aggregate([{

That could also be a "quick fix" to this problem