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

$begins Mango Operator #3369

Closed
skeyby opened this issue Feb 15, 2021 · 1 comment
Closed

$begins Mango Operator #3369

skeyby opened this issue Feb 15, 2021 · 1 comment

Comments

@skeyby
Copy link

skeyby commented Feb 15, 2021

Summary

It would be cool to have a sugar-operator called $begins that is internally implemented as an AND of $gte a $lt to find any value starting with a desired pattern.

Desired Behaviour

The usage il something like this: let's suppose we want to find all people with surname starting with "Branca" either for autocompletition purpose or just because the user may have a second surname. Actually one could only do:

"Surname": {
 $eq: "Branca" 
}

That wouldn't find either "Brancatelli" nor "Branca SecondSurname"

The only solution would be to:

"Surname": { 
  $regex: "Branca"
}

That is unindexed.

Possible Solution

As in summary a solution could be to implement a sugar-operator called $begins that internally gets mapped to an AND-combination of $gte and $lt with an upper character as an upper bound. So, calling:

"Surname": {
 $begins: "Branca" 
}

would be translated in

$and: [
 { "Surname": { $gte: "Branca" } },
 { "Surname": { $lt: "Branca\ufff0" } }
]

That would use the index as expected.

@nickva
Copy link
Contributor

nickva commented Nov 13, 2023

This was implemented by @willholley in #4810!

Closing as completed.

@nickva nickva closed this as completed Nov 13, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants