I need to version entries to a FireStore collection, and I'm not sure the best way to structure the data so I can load back a list of the latest versions only.
Say we have a collection of Item
s. Each Item
will have it's ID, title, content and a revision number. Each revision will change the content, and bump the rev number.
What is the best way to store the revisions?
- Each revision as a brand new
Item
in the collection- it would have to have some link back to the parent ID
- Or an
Item
contains its own collection,Revisions
, each with all the data
How would I get a list of Item
s that shows ONLY the latest revision?
For option 2 I suppose you could order by dateCreated
and limitToFirst(1)
?
But I would have to load the main collection, and then loop each entry and load its latest item - not the end of the word, but feels like there is a better way.