google-cloud-firestoregoogle-cloud-datastoreobjectify

Objectify - How to use new Firestore in Datastore mode filters !=, IN, NOT_IN


In the objectify docs it shows these operators:

// Operators are >, >=, <, <=, in, !=, <>, =, ==
List<Car> cars = ofy().load().type(Car.class).filter("year >", 1999).list();
List<Car> cars = ofy().load().type(Car.class).filter("year >=", 1999).list();
List<Car> cars = ofy().load().type(Car.class).filter("year !=", 1999).list();
List<Car> cars = ofy().load().type(Car.class).filter("year in", yearList).list();
// Note that Objectify 6+ does not provide != or IN (this is not yet supported by the underlying Cloud SDK)

Two questions:

  1. I think the comment about != or IN might be outdated because the google docs show these as supported but only in Firestore in Datastore mode (which at this point, every/most database should be that since the original Datastore is being auto-migrated to Firestore). So I assume the != and IN filters should just work if we use them in objectify?

  2. What is the way to write a NOT_IN filter? It is also something new in Firestore in Datastore mode. Is this how you would write it: .filter("year not_in", yearList)?


Solution

  • From the code & release notes, you can use !in for NOT_IN.