3
votes

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 Items. 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 Items 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.

2
@FrankvanPuffelen Do you have any thoughts on this, or any pointers? Not finding much on the interwebs... - Matt Bryson
See my answer below on the Firebase team's position on this. - Adam Hurwitz

2 Answers

1
votes

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.

0
votes

Based on Doug Stevenson's advice from the Firebase team, he advises in this answer to a StackOverflow question to create a separate project per development environment. This is what I've outlined thus far for my project.

QA_PROJECT

  • CONTENT_COLLECTION
    • feeds_document
    • sources_document
  • USERS_COLLECTION
    • userOne_document
    • userTwo_document

PROD_PROJECT (same sub-hierarchy as above)

When I'm testing out a new feature I can take a "snapshot" of the stable version using Firestore's export/Import capabilities in order to have a backup if required.