I am working with NodeJS on Google App Engine with the Datastore database.
I am using composite query filter and just need a basic "OR" condition.
Example: Query Tasks that have Done = false OR priority = 4
const query = datastore.createQuery('Task')
.filter('done', '=', false) //How to make this an OR condition?
.filter('priority', '=', 4);
However, according to the documentation:
Cloud Datastore currently only natively supports combining filters with the AND operator.
What is a good way to achieve a basic OR condition without running two entirely separate queries and then combining the results?
UPDATE
I have my solution described in detail here in my other post. Any feedback for improvements to the solution would be appreciated since I'm still learning NodeJS.
Not currently possible to achieve a query with an
OR
condition - this is what the note you quoted means.Some client libraries provide some (limited) support for
OR
-like operations. From Restrictions on queries:But AFAIK no such library is available for NodeJS.
If you only have a need for a few specific such queries one possible approach would be to compute (at the time of writing the entities) an additional property with the desired result for such query and use equality queries on that property instead.
For example, assuming you'd like a query with
OR
-ing the equivalents of these filters:.filter('status', '=', 'queued')
.filter('status', '=', 'running')
You could compute a property like
not_done
every timestatus
changes and set it totrue
ifstatus
is eitherqueued
orrunning
andfalse
otherwise. Then you can use.filter('not_done', '=', true)
which would have the same semantics. Granted, it's not convenient, but it may get you past the hurdle.