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

$eq: null works differently to mongodb #50

Open
forivall opened this issue Oct 18, 2024 · 0 comments
Open

$eq: null works differently to mongodb #50

forivall opened this issue Oct 18, 2024 · 0 comments

Comments

@forivall
Copy link
Contributor

forivall commented Oct 18, 2024

With MongoDB, $eq: null matches fields that are null and fields that are missing. For example, with the following mongosh operation

db.testcollection.find({ testvalue: null })

on a test db with the following document,

{
   "_id" : ObjectId("671206436e1e7e947a9b571e"),
   "otherwise_this_is_empty": true
}

then mongodb will return the document.

However, with UCAST (and downstream CASL), this document will not match, as testvalue will be undefined.

There's a few workarounds, like using $in: [undefined, null] or defining a custom compare function to buildMongoQueryMatcher (in CASL).

I have a test case prepared at forivall@1d1c5bb (branch)

If this is the intended behaviour, then I'd at least like the comparePrimitives method to be explicitly exported, so that the custom compare function can just be (a, b) => a == null && b == null ? 0 : comparePrimitives(a, b)

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