Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NDB: Sort query results

In App Engine NDB, I am querying entities that have a repeated property. I would like to order the result by the length of the array representing that property.

What I wish I could do:

Entity.query(...).order(len(Entity.repeatedProp))
like image 489
David Mihal Avatar asked Jan 27 '26 08:01

David Mihal


1 Answers

You'll need to add an ndb.IntegerProperty() to your entity where you will store the length of the repeated property. Every time you change your repeated property, you'll need to update the stored length. Then you sort based on that stored length.

You could probably use a computed property, but I've never used one of those so I'm not sure.

like image 169
gaefan Avatar answered Jan 28 '26 23:01

gaefan



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!