How to Query a repeated property with a list object in google appengine ndb

mehulkar Source

I need to construct a logical query with a repeated property and can't get it to work. I have a list object with topics.

topics = [u'string1', u'string2', ...]

I have a query object:

videos = Video.query()
=> 19

topics is a repeated string property

class Video
  topics = ndb.StringProperty(repeated=True)

I want to return videos that have a topic string1 OR string2. I also don't know the length of the list object before or I could just construct the query the long way with logical operators.

I tried doing this like the documentation suggests

videos.filter( Video.topics.IN([topics]) )

but that throws the error that IN expected a string not a list object.

How do I do this?



answered 6 years ago Guido van Rossum #1

Looks like topics is already a list. So you need to pass it without another list around it:

videos.filter( Video.topics.IN(topics) )

answered 1 year ago rcmcastro #2

For an arry of topics, you can use:


Or for a single string:

Video.query(Video.topics == topic)


comments powered by Disqus