We have a collection, let's say, called "restaurants". For each restaurant, there's a subcollection called "visited", where we capture the userId of each user who has visited that restaurant. Here's how the database looks like:
We picked creating a subcollection over using an array inside of restaurants because we expect this number to increase up to very large document size. Besides, we are not sure about the performance of queries involving really long arrays (100s of 1000s of them).
Anyway, so now that we have these sub-collections called "visited", we are able to use collection group queries with indexes to do something like "find all restaurants visited by user: "abcdxyz" with a "==" query, and in a certain order lets say, sorted by the visitedOn date/time.
Here's what we tried running in python:
db.collection_group(u'visited').where(u'userId', u'!=', u'idoftheuser').order_by('visitedOn', direction=firestore.Query.DESCENDING)
When we run this to find restaurants that were never visited by this user, Firestore is throwing the following error:
ValueError: Operator string '!=' is invalid. Valid choices are: <, <=, ==, >, >=, array_contains
Is this true? Why would they not allow "!=" queries when they are allowed in individual collections? How can we get around this issue? We really don't want to make any changes to our database model anymore. Too much back and forth already.
Any suggestions?