You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@couchdb.apache.org by GitBox <gi...@apache.org> on 2021/02/15 11:27:54 UTC

[GitHub] [couchdb] skeyby opened a new issue #3369: $begins Mango Operator

skeyby opened a new issue #3369:
URL: https://github.com/apache/couchdb/issues/3369


   
   ## 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.
   
   


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org