3

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.

Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807
Matt Bryson
  • 2,286
  • 2
  • 22
  • 42

2 Answers2

1

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.

Matt Bryson
  • 2,286
  • 2
  • 22
  • 42
  • Hello @Matt Bryson, you did this using Cloud Functions or private server? if you use Cloud Functions can you share how you keep the top level synced with the latest version inside revision? – Tarcisio Wensing Feb 15 '18 at 22:00
0

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.

AdamHurwitz
  • 9,758
  • 10
  • 72
  • 134