Twitter LogoFacebook Logo
Firestore - Get Collection
Use the Get Collection and the Listen to Collection nodes to get documents from a collection.
By: King

Hello, in this tutorial, I will show you how to get documents from a collection.

To Get Documents from a collection, use the Get Collection node. It has 4 pins: 

1 for the path to the collection

1 for queries to filter data
2 for callbacks to handle executions when the documents were retrieved or when it fails to retrieve it

Image from Codeible.com

The Collection Path is a String array that represents the path to the document in Firestore. Every even element points to a collection and every odd element points to a document.

Query is an array used  to filter the documents in the collection. The Query nodes are included in the FBP Plugin.

The On Documents Received callback gets called when the documents are retrieved.

The On Fail to Retrieve Collection callback gets call when it fails to obtain the documents.

Image from Codeible.com

Queries

To build the query, start with the Begin Get Collection Query node.

Image from Codeible.com

Then add queries using any of these nodes:

Where Equal to String
Where Equal to Boolean
Where Equal to Number
Where Greater Than This String
Where Greater Than This Number
Where Greater Than or Equal to This String
Where Greater Than or Equal to This Number
Where Less Than This String
Where Less Than This Number
Where Less Than or Equal to This String
Where Less Than or Equal to This Number
Order By
Limit

Image from Codeible.com

Adding the Callbacks

Image from Codeible.com

To create these callbacks, click and hold on the callback pin from the node. Then drag and let go on an empty spot on the blueprint.

Select “Add Event” then “Add Custom Event.” That will create the event node fit for the callback.

Image from Codeible.com

The On Documents Received callback gets called when the documents are retrieved. You will need to use the "Get Document From Collection" node to extract all t he documents from the Collection Snapshot.

After use the For Each Loop node to loop through all the documents.

To get the fields from each document, refer to Get Document documentation.

Basically, you will need to use these nodes:

• Get String
• Get Number
• Get Boolean
• Get String Array
• Get Number Array
• Get Boolean Array
• Get Map

Attaching a listener to the collection

You can also attach a listener to a collection and listen to any changes made to it by using the “Listen To Collection” node. This way, you’ll be able to update information in real-time every time a document is added, removed, or modified.

Image from Codeible.com

It has 5 pins

1 for the path to the collection
1 for queries to filter data
3 for callbacks that will be called when a document is added, modified, or deleted from the collection

Image from Codeible.com

The Collection Path is a String array that represents the path to the document in Firestore. Every even element points to a collection and every odd element points to a document.

Query is an array used  to filter the documents in the collection. The Query nodes are included in the FBP Plugin.

The On Documents Added callback gets called when a document is added to the collection and it fits the queries you added.


It returns a Document Snapshot that you can use to get the contents inside the document.

The On Documents Modified callback gets called when a document is modified, either by adding or removing fields.

It returns a Document Snapshot as well.

The On Documents Deleted callback gets called when a document is deleted from the collection and it meets the query parameters that were set.

To create these callbacks, click and hold on the callback pin from the node. Then drag and let go on an empty spot on the blueprint.

Select “Add Event” then “Add Custom Event.” That will create the event node fit for the callback.

Image from Codeible.com

Sign In