mongoose-delete icon indicating copy to clipboard operation
mongoose-delete copied to clipboard

Model.restore( ) method bug .

Open DMT-011 opened this issue 1 year ago • 2 comments

When using this method it does not change the value of deleted field in mongodb to false instead it deletes this field.

DMT-011 avatar Jun 24 '24 11:06 DMT-011

Fixed here: https://github.com/dsanel/mongoose-delete/pull/157

mareksuscak avatar Aug 15 '24 11:08 mareksuscak

Depending on wether use$neOperator is set to true or false we get defective results either way at the moment:

use$neOperator: false countDocuments (1), countDocumentsWithDeleted (6), countDocumentsDeleted (5) ==> restore() countDocuments (1), countDocumentsWithDeleted (6), countDocumentsDeleted (3) --> countDocuments should be (3)!

use$neOperator: true countDocuments (1), countDocumentsWithDeleted (6), countDocumentsDeleted (5) ==> restore() countDocuments (3), countDocumentsWithDeleted (6), countDocumentsDeleted (5) --> countDocumentsDeleted should be (3)

It would be great if that/a solution could be published soon :) Thanks!

scaszoo avatar Oct 09 '24 15:10 scaszoo

Image

if u still having this issue, based on this snippets, u should query the schema first and call restore() afterwards.

const restored = await documentModel.findOneDeleted({ _id: id })
restored?.restore()

this will make the deleted: false. otherwise

await documentModel.restore({ _id: id })

this will make the deleted attribute become undefined

PL-Aufi-Fillah avatar Jun 17 '25 02:06 PL-Aufi-Fillah

Hey @dsanel would you be willing to make some of us maintainers of this repository and the npm package so we can release some of the fixes from open PRs?

mareksuscak avatar Jun 17 '25 12:06 mareksuscak