Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

To save documents containing an array of objects using Firebase Cloud Firestore and Functions, follow these steps:

  1. Define your data model: Before you start writing any code, you should define the data model for your documents. The data model should include all the fields you want to store in your document, including the array of objects.

  2. Create a Cloud Function: Once you have defined the data model, you need to create a Cloud Function that will save the document to the Firestore collection. You can use the Firebase CLI to create the function.

  3. Connect to Firebase Firestore: In your Cloud Function, you need to connect to your Firebase Firestore by initializing the Firestore Admin SDK.

  4. Save the document: Once you have connected to Firebase Firestore, you can save the document to the collection. To save the document containing an array of objects, you can use the set() or update() method. If you are using the set() method, make sure to set the merge option to true so that any existing fields are not overwritten.

  5. Test the function: Finally, you need to test the Cloud Function and make sure it is saving the document correctly. You can use the Firebase CLI to deploy the function and test it locally or in the cloud.