2
votes

In the docs it says that there is no way to query for entities that do not include a tag equal to a specific value: https://developers.google.com/appengine/docs/python/ndb/queries#neq_and_in

I have a set of entities, each entity has a set of tags. I need to find those entities WITHOUT a specific tag. Is there any workaround for the ndb query limitation?

1
If your set of tags is small, or if the set of tags you want to do your "WITHOUT" query for is small, add a "not_tags" property (a list property or "repeated=True" if using ndb) to the entity as well. This would contain the inverse of your tags property, or the appropriate WITHOUT subset. As Peter mentions below, you will then have an index that you can query. If your set of tags is large, this probably won't work.Mark Rajcok

1 Answers

2
votes

Every time you create/update an entity, it's indexes are updated based on values of it's properties.

If a property does not exist or a list property does not contain a value (= tag in your case), then there is no entry for it in the index. Since queries rely in indexes to find stuff, it will not be found.

This is not a NDB query limitation, but rather a GAE datastore limitation, meaning that all APIs accessing it have this limitation (Java/Python/Go , low-level API, etc..).

AFAIK, there is no direct way around it. You can code around it by getting all Articles and then checking in code for those missing the tag, but this can be costly depending on the number of articles.

You might want to create a new question and describe the problem in detail from application perspective: what is the end result you are trying to achieve?