I need to add tags to documents in Firestore.
These tags are created by admin users, and each Tag is a document in a Tags collection.
One or more of these tags are then applied to other documents, say Item documents.
We then need to be able to query the Items for ones that contain a specific Tag id, and have other range filters - date created within a range, order by date created, user id matches a specific user etc.
How would I structure the Item tag data so it can be queried?
- An Array property can't be queried, so that wont work.
- A map or set must be pre indexed, which also won't work as its dynamic data.
- If I had a pre-defined number of allowable tags, and save each as a property, - tag1,- tag2,- tag3etc, I could try to query that, but- ORis not supported...
- I could add another collection, that holds the one-to-many relationships - say ItemTags, that has{itemId, tagId}, and then Query that first to get a list ofItemids, but again, how do I then user that list of ids to filter theItemscollection?
 
- say 
I don't want this client side as the data is going to be very large.
UPDATE:
The Tags are hierarchical, and you can only have one tag at each level.  So one possible option is to have top level fields on the Item: tag1, tag2, tag3 etc with a pre defined limit. Then when the Item is created, the correct tag levels are inserted, and when its queried, we would need to know which level tag the user is looking for and we could then query item.tag1 = levelOneTag AND item.tag2 = levelTwoTag.
Not ideal as it limits the level, but I'm pretty sure 10 would cover it.
 
    