Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Broken with MongoDB version 6 #38

Open
timb-103 opened this issue May 4, 2024 · 0 comments
Open

Broken with MongoDB version 6 #38

timb-103 opened this issue May 4, 2024 · 0 comments

Comments

@timb-103
Copy link

timb-103 commented May 4, 2024

In mongo version 6, they have made breaking changes to findOneAndUpdate (https://github.com/mongodb/node-mongodb-native/blob/main/etc/notes/CHANGES_6.0.0.md#findoneandx-family-of-methods-will-now-return-only-the-found-document-or-null-by-default-includeresultmetadata-is-false-by-default).

Now, it simply returns the document without any metadata, so in the following res.value will be undefined, it simply needs to return res.

Also, returnOriginal has been removed and should be replaced with returnDocument: 'before'

  protected async lockNext() {
    const sleepUntil = moment().add(this.config.lockDuration, 'milliseconds').toDate();
    const currentDate = moment().toDate();

    const res = await this.getCollection().findOneAndUpdate({
      $and: [
        { [this.config.sleepUntilFieldPath]: { $exists: true, $ne: null }},
        { [this.config.sleepUntilFieldPath]: { $not: { $gt: currentDate } } },
        this.config.condition,
      ].filter((c) => !!c),
    }, {
      $set: { [this.config.sleepUntilFieldPath]: sleepUntil },
    }, {
      returnOriginal: true, // return original document to calculate next start based on the original value
    });
    return res.value;
  }

If you could please update this so we can upgrade to mongo 6 that would be appreciated! Thanks.

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

No branches or pull requests

1 participant