Skip to content

🌳 Feature - Enhance plugin to include "deletedId" on deleted docs#2

Merged
taherashorna1 merged 18 commits intomasterfrom
feature/enhance-deleted-Id
Jul 10, 2025
Merged

🌳 Feature - Enhance plugin to include "deletedId" on deleted docs#2
taherashorna1 merged 18 commits intomasterfrom
feature/enhance-deleted-Id

Conversation

@taherashorna1
Copy link
Collaborator

@taherashorna1 taherashorna1 commented Jul 1, 2025

AB#254511

We are upgrading mongoose-delete plugin to add deletedId option for the restoration of locations

This pull request introduces support for a new deletedId field in the mongoose_delete plugin. The changes include updates to the schema, methods, and static functions to handle the deletedId field, as well as comprehensive tests to validate the new functionality.

Schema and Method Enhancements:

  • Added support for a deletedId field in the schema, which can be enabled via the deletedId option. This field is indexed if specified. (index.js: [1] [2]
  • Updated delete and deleteById methods to accept and process deletedId alongside deletedBy. The deletedId value is prioritized if both are provided. (index.js: [1] [2] [3]
  • Modified the restore method to unset the deletedId field upon restoration. (index.js: index.jsL290-R351)
  • Adjusted the $unset operation to include deletedId when restoring documents. (index.js: index.jsL315-R371)

Tests:

  • Added new test cases to validate the functionality of the deletedId field, including scenarios for deletion, restoration, and type customization. These tests ensure proper handling of deletedId in various configurations. (test/index.js: test/index.jsR551-R701)

Copilot AI review requested due to automatic review settings July 1, 2025 23:22

This comment was marked as outdated.

Copy link

@AndrewFinlay AndrewFinlay left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is looking really good Tahera. It might look like there's a heap of feedback on this but it's really just a bunch of tweaks here and there. It's a bit of a tricky one this as the library is obviously really old now and that can make it hard to know what we should update and what we should leave be.
That said I think we should be safe to make some of our own updates to it, and eventually we should make it async/await and simply drop the callback based stuff. We'd have to do that anyway if we're ever going to upgrade Mongoose.

AndrewFinlay
AndrewFinlay previously approved these changes Jul 8, 2025
Copy link

@AndrewFinlay AndrewFinlay left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is great, thanks for the hard work!

Comment on lines -6 to -14
test:
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [ubuntu-20.04, ubuntu-22.04]
node: [16, 18, 20]
mongodb-version: ['4.4.18', '5.0.14', '6.0.4']
name: Node ${{ matrix.node }} MongoDB ${{ matrix.mongodb-version }}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤔 I don't know how much of this we can change because if we merge this back to the upstream repo then it will still need to run the same kind of multi-os multi-runtime checks.

That said we could probably update some of the targets in here. I don't think any of the ubuntu-20.04 targets ran so we should be good to drop that. If you look at https://github.com/actions/runner-images it will list what images are available for the os setting. I'd go with Ubuntu 22 & 24.

According to the link above it says that it supports the latest 3 LTS nodejs versions. If you take a look at https://nodejs.org/en/about/previous-releases you'll see a chart showing the currency of Node releases. Only even numbered releases are ever used as Long Term Support (LTS) releases, 26 doesn't exist yet but it's planned, 24 is in the current state until October meaning it won't be an active LTS release until then, so to test with the last three LTS releases right now would be 18, 20, and 22.

Finally it lists a bunch of MongoDB versions. I think to remove any of the old versions without a major bump for the library would be against semver as you're removing a guarantee of compatibility. So your best course of action for now is to add Mongo 7 & 8. I think what's available will depend on what's included in the Ubuntu image, Ubuntu 22 is known as Jammy & Ubuntu 24 is known as noble and I don't know if noble has support going all the way back. That said I think the latest version for Mongo 7 is 7.0.21, and for Mongo 8 it's 8.0.11. If you run into trouble with noble I'd drop Ubuntu 24 from the matrix until you can do a major bump for mongoose delete.

taherashorna1 and others added 6 commits July 9, 2025 12:37
Co-authored-by: AndrewFinlay <AndrewFinlay@users.noreply.github.com>
Co-authored-by: AndrewFinlay <AndrewFinlay@users.noreply.github.com>
package.json Outdated
"main": "index.js",
"scripts": {
"test": "mocha",
"test:ci": "MONGODB_TEST_URI=mongodb://localhost:27017/lighthouse_mongoose_delete_test?directConnection=true mocha --exit",

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

❓ Is this needed to run as a ci test?

// mongodb: { deleted: true, name: 'Bitey', deletedId: ObjectId("61fc42a56b4a6670076b16bf")}

// Find all pets deleted as part of this action
const deletedPets = await Pet.findWithDeleted({ deletedId: actionId });

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤏 I think findWithDeleted might be a LH function yeah? That probably means you'll need to have your own equivalent implementation in your docs.

Copy link
Collaborator Author

@taherashorna1 taherashorna1 Jul 9, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

findWithDeleted is a mongoose-delete function that can be used instead of find, so I think this is fine here?

Copy link

@AndrewFinlay AndrewFinlay left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, nice work on this. I'll check in with Todd next time I speak with him about putting this up as a PR to the original repo

@taherashorna1 taherashorna1 merged commit 0ed5792 into master Jul 10, 2025
12 checks passed
@taherashorna1 taherashorna1 deleted the feature/enhance-deleted-Id branch July 10, 2025 04:26
taherashorna1 added a commit that referenced this pull request Sep 3, 2025
🌳 Feature - Enhance plugin to include "deletedId" on deleted docs
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants