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?
Item
in the collection
Item
contains its own collection, Revisions
, each with all the dataHow 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.
In the end I went with the sub collection of Revisions
. The main doc kept a reference to the latest / current revision.
We simplified the requirements, so we only needed top level data in the lists, not data from the revisions.