Coding⏱️ 2 min read📅 2026-06-03

How to Fix: How to update an "array of objects" with Firestore?

To update an array of objects in Firestore, you can use the set method and provide a new object with the updated array. You can also use the update method if you want to update only specific elements.

Quick Answer: Use the set method with a new object containing the updated array: db.collection('proprietary').doc(docID).set({ sharedWith: [{ who: 'third@test.com', when: timestamp }] });

To update an array of objects in Firestore, you need to use the update method and specify the path to the document and the new value for the array field.

🛠️ Step-by-Step Verified Fixes

Method 1: Using the Update Method

  1. Step 1: Get a reference to the document using collection().doc().

Method 1: Using the Update Method (continued)

  1. Step 2: Use the update method to update the array field. You can use the $ operator to reference the array field.

Method 1: Using the Update Method (continued)

  1. Step 3: Provide the new value for the array field in the .set method.

For example, to add a new record to the sharedWith array, you can use the following code:

firebase.firestore().collection('proprietary').doc(docID).update({ sharedWith: firebase.firestore.FieldValue.arrayUnion([{ who:  

Did this fix your problem?

If not, try searching for specific error codes.

🔍 Search Error Database

❓ Frequently Asked Questions