longshotlabs / simpl-schema

A JavaScript schema validation package that supports direct validation of MongoDB update modifier objects
https://www.npmjs.com/package/simpl-schema
MIT License
560 stars 114 forks source link

Cannot read property '$set' of undefined #474

Open knoxgon opened 1 year ago

knoxgon commented 1 year ago

I'm trying to execute existing operations upon migrating from 1.13.1 to 3.4 and certain update operations fail to execute and throws the same error.

Everything up to version 3.2 seems to work fine. From 3.3 and upwards (3.4 the latest as of today) have this problem.

This issue seems to coming from aldeed:collection2-core package where the selector mapping is performed against ObjectID, _id or string.

E.g., it totally ignores the logical operators such as $and and $or. So the docId is always null within the named cases.

The package aldeed:collection2-core/collection2.js has not been updated for some years. Although, since it worked with the earlier simpl-schema versions, I'm not entirely sure if the problem actually coming from that package. I guess the way data is passed to that object from simpl-schema introduces anomalies.

Filename: aldeed:collection2-core/collection2.js

image

This is the operation where I perform the update

MyTestCollection.update(
    { "$and": [{"$or": [{"$and": [{"currlaunch": "dataset"}] }] }, {"groupid": {"$ne": "98n2z62tgb519"} }] },
    { "$push": { "posit": {.....objects....}, "emps": { "$each": ['a', 'b', 'c']} }, "$set": { "iter.datecol": Date.now() } },
    { multi: true, upsert: false }
)

The same operation works on all versions except version 3.3 and 3.4.

And for the named reason, the obj property becomes undefined.

Filename: simpl-schema/src/validation/requiredValidator.ts image

github-actions[bot] commented 1 year ago

Thank you for submitting an issue!

If this is a bug report, please be sure to include, at minimum, example code showing a small schema and any necessary calls with all their arguments, which will reproduce the issue. Even better, you can link to a saved online code editor example, where anyone can immediately run the code and see the issue.

If you are requesting a feature, include a code example of how you imagine it working if it were implemented.

If you need to edit your issue description, click the [...] and choose Edit.

Be patient. This is a free and freely licensed package that I maintain in my spare time. You may get a response in a day, but it could also take a month. If you benefit from this package and would like to see more of my time devoted to it, you can help by sponsoring.

aldeed commented 1 year ago

Does it matter what schema is attached? Can you post an example schema that will reproduce the issue?