Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NDB querying results that start with a string

Working with Google App Engine's NDB, I'm looking to query for all items that start with a user-inputted string. Example:

abc_123
abcdefg
123abc

Querying for "abc" should return abc_123, abcdefg (however, not 123abc as it doesn't start with "abc")

I previously used the code below for a similar but different purpose:

q = q.filter(order._properties[kw].IN(values_list))

which filtered for all values in values_list that were in kw, I am now looking to filter for all values that start with a string that are in kw.

like image 728
adiadi Avatar asked Dec 31 '25 17:12

adiadi


1 Answers

Try:

Kind.query(ndb.AND(Kind.property >= "abc", Kind.property <= "abcz"))
like image 94
dragonx Avatar answered Jan 02 '26 06:01

dragonx



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!