1

I have the following model for a Firestore document:

{
  name: "test",
  isActive: true,
  items: [
   {
     id: "123",
     itemName: "testItem",
     qty: 1
   },
   {
     id: "555",
     itemName: "anotherItem",
     qty: 5
   }]
}

Now that Firestore allows to work with nested arrays (via arrayRemove / arrayUnion), I am wondering whether this is possible also through AngularFire2.

Or the only way so far is to import Firebase and using it straight ahead?
Like:

this.firestore.collection(<collectionName>).doc(<docID>).update({
 answers: firestore.FieldValue.arrayUnion(<AnswersObject>)
});

Moreover is such a model with nested array legit in FIrestore or should it rather be structured in a different way?

2 Answers 2

1

Unfortunately, AngularFire2 does NOT yet support this. You can verify this by checking out the source code.

Or, if you're lazy like me and don't feel like digging through trying to find it on GitHub... what I did to double check was to download the whole repo as a ZIP file, extract, and open folder in VS Code. Searching the whole folder for FieldValue or arrayUnion returns nothing - those words don't exist in the entirety of the source.

So for right now, you're correct about needing to stick with the default Firebase/Firestore package. And nested arrays are definitely a "legit" thing, but like everything else, when to use it depends on your situation - and I don't feel qualified or experienced enough to evaluate your situation and make a strong recommendation.

Sign up to request clarification or add additional context in comments.

Comments

1

I struggled with this a while, it seems angular's documentation is always behind. I updated an item the array like this, the array is called accomodation and it is within the day object.

this.data.firestore.doc(`days/${accommodation.day}`)
  .update({
    accommodation: [
      accommodation
    ]
  });

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.