Skip to content

How to combine different paths in firestore version 9

I was using firestore version 8 and used the following code to create alternations in code:

const subQuestionRef = DB.collection('groups')

if(someCondition) {
} else {

I couldn’t find a way to create such alternations in firestore version 9.

Do you know how to create alternations in version 9?


the way I would approach this with V9 will be the follow:

const subQuestionRef = collection(db, `groups/${groupId}/questions/${questionId}/subQuestions`)

if (someCondition) {
  setDoc( doc(subQuestionRef, uid), {something} )
} else {
  setDoc( doc(subQuestionRef, subQuestionId), {somethingElse} )

We now have a really nice API reference in V9.

doc() reference: