dsanel / mongoose-delete

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

findDeleted error #136

Closed johnH872 closed 9 months ago

johnH872 commented 1 year ago

When I use findDeleted, I found all records instead of records with deleted = true

Luanardo commented 1 year ago

Looks like findDeleted returns all records except records that have deleted = false. So when I used restore it removed the field 'deleted'. That causes the record I restored to still be found by findDeleted.

vinhhathai commented 1 year ago

same with me, when I used restore, the field 'deleted' was removed instead of being changed to 'false'."

saman-waruka commented 1 year ago

same with me, when I used restore, the field 'deleted' was removed instead of being changed to 'false'."

I found the same.

dsanel commented 9 months ago

Because we are using this query to get all "deleted" documents (here) this is expected behavior.

return Model[modelMethodName].apply(this, arguments).where('deleted').ne(false);

You can try to use TestSchema.plugin(mongoose_delete, {overrideMethods: 'all', use$neOperator: false}); to get only deleted===true documents