cult-of-coders / redis-oplog

Redis Oplog implementation to fully replace MongoDB Oplog in Meteor
MIT License
377 stars 81 forks source link

Exception when a modifier with undefined values is used #398

Open xolott opened 1 year ago

xolott commented 1 year ago

When this modifier is used, redis-oplog throws an exception:

const modifer = {
    $addToSet: undefined
};

Collection.update(selector, modifier);

Exception:

Exception in setInterval callback: TypeError: Cannot convert undefined or null to object
    at Function.keys (<anonymous>)
    at packages/cultofcoders:redis-oplog/lib/utils/getFields.js:12:20
    at Array.forEach (<anonymous>)
    at getFields (packages/cultofcoders:redis-oplog/lib/utils/getFields.js:10:29)
    at ns.Collection.update (packages/cultofcoders:redis-oplog/lib/mongo/Mutator.js:198:32)
    at ns.Collection.update (packages/cultofcoders:redis-oplog/lib/mongo/extendMongoCollection.js:40:35)

I think the issue is in this line: https://github.com/cult-of-coders/redis-oplog/blob/58ba4266f4978f061081c641efe89ce9db9b791b/lib/utils/getFields.js#L11

Something like this should work.

    const isNil = (value) => value === null || value === undefined;
    Object.entries(mutator).forEach(function ([op, params]) {
        if (op[0] == '$' && !isNil(params)) {

A modifier with a value undefined is valid for the mongo driver. It just ignores it.

github-actions[bot] commented 1 year ago

Thank you for submitting this issue!

We, the Members of Meteor Community Packages take every issue seriously. Our goal is to provide long-term lifecycles for packages and keep up with the newest changes in Meteor and the overall NodeJs/JavaScript ecosystem.

However, we contribute to these packages mostly in our free time. Therefore, we can't guarantee you issues to be solved within certain time.

If you think this issue is trivial to solve, don't hesitate to submit a pull request, too! We will accompany you in the process with reviews and hints on how to get development set up.

Please also consider sponsoring the maintainers of the package. If you don't know who is currently maintaining this package, just leave a comment and we'll let you know

xolott commented 1 year ago

I created the PR #399 with what I think would fix the issue