Cloud Firestore
Learn how to perform CRUDL operations with Cloud Firestore
Open the project and create a new Action. Choose the Code action step and insert a code that will load your Firestore collection.
const collection = await firebase.firestore().collection("collectionName").get();
const result = [];
collection.forEach(doc => {
const data = doc.data();
result.push({ id: doc.id, ...data });
});
return result;

Adding a Load data action
Then, press the Run Action button and open the Result section. You must have your collection's data loaded there.
To fetch data about a certain document, start with Creating a new Action and selecting the Code step.

Adding a Read the data action
Insert the code below to read the document's data:
const doc = await firebase.firestore().collection('collectionName').doc('docID').get();
return doc.data();
Press the Run Action button and open the Result section. You will see the document's data.
Let's create a new record in Firestore. First of all, we need to create a new Action. Choose a Code action type and insert the code that will create a new record in your Firestore.
const newUser = { name: "Nik" };
const doc = await firebase.firestore().collection("collectionName").add(newUser);
return doc.id;

Adding a Create record action
Press the Run Action button and open the Result section. You must have a new record there.
Let's delete a record from Cloud Firestore. Create a new action and select a Code action step. Type in a code:
await firebase.firestore().collection('collectionName').doc('docID').delete();
Press the Run Action button and open the Result section to check that the record has been deleted.
You can update the data in Cloud Firestore with 2 methods:
set()
and update()
. The difference is, set()
will overwrite the whole document.update()
will update only certain fields that need to be updated. Let's check both of the approaches for updating your Firestore data.set()
const doc = await firebase.firestore().collection('collectionName').doc('docID').set({
docField: newFieldValue
});
In case you do not want to overwrite your data, you can add
merge: true
to your code, so that you only update the required fieldsupdate()
For the update() method, type in the below Code:
const doc = await firebase.firestore().collection('collectionName').doc('docID').update({
docField: newFieldValue
});
Click Run Action and check the Result section for the outcome.

Adding an Update Step and checking the Result
All the other operations with the Firestore collections like Filter, Order can be done via the Firestore API. You can find an API reference here.
More useful articles on how to further manage your data:
Last modified 1mo ago