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

Implement $expr operator #237

Open
omanizer opened this issue Oct 21, 2021 · 2 comments
Open

Implement $expr operator #237

omanizer opened this issue Oct 21, 2021 · 2 comments

Comments

@omanizer
Copy link
Contributor

This may be a can of worms, but it would be a very nice addition to this library. It would be nice to do a direct comparison on a record's fields with each other rather than only comparing a single column with a static value.

In SQL this functionality is trivial:

SELECT * from my_table WHERE points_total > points_used

Mongo provides the $expr operator for this purpose, which is a newer feature:

db.my_collection.find({
  $expr: {
    $gt: ['$points_total', '$points_used']
  }
})

This allows finding all records that have points remaining without having to manually implement a points_remaining column. It's technically an "aggregation" functionality but since it's been made available in the find operation it could make sense to include here as well.

Thoughts?

@crcn
Copy link
Owner

crcn commented Oct 30, 2022

Yeah I think this would be great! Though, I don't have much time to work on this right now. Happy merge a PR into Sift though.

@kethan
Copy link

kethan commented Jul 28, 2024

https://github.com/kethan/uqry

You can try this under 1kb with aggregation. It has $expr too.

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

3 participants