The Note in != and IN Operations documentation warns that Entities without a property are not indexed. It is more efficient to choose a sentinel value such as "_no_name_" that will be indexed, and search for that. Of course your remaining code must process sentinel values as blank where appropriate.
How do I query datastore entities that have any value for a certain property efficiently?
-
20-06-2023 - |
質問
I have the following model
class User(ndb.Model):
name = ndb.StringProperty()
I can query all the User entities that have no name by doing the following:
users_without_names = User.query(User.name == None).fetch(100)
But how do I query User entities with names, without using != None?
I also need to add another inequality filter on another property, and using != will translate into an equality filter, so I'd like to avoid !=.
解決 2
他のヒント
You could search for all names > ""
users_with_names = User.query(User.name > "").fetch(100)
所属していません StackOverflow