Twitter LogoFacebook Logo
Firestore - Get Document
Using the Get Document and Listen To Document nodes to retrieve contents from a document.
By: King

Hello, in this tutorial, I'll show you how to get contents from a Document using the FBP Firebase Plugin for Unreal Engine.

Get Document

Image from Codeible.com

To get documents once, use the "Get Document" node. 

It has 3 pins: 

1 for the Document Path in Firestore

2 callbacks to handle executions after the delete operation is successful or not

The Document 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.

The On Document Retrieved Callback gets called when the contents of the documents are retrieved. It returns the document id and a document snapshot containing all the data.

The On Fail to Retrieve Document Callback gets call when an error occurred during the retrieval process. We can use the Error Message string that it returns to see what type of error occurred.

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

Retrieving the contents

To get the data from the document snapshot, use any of the following nodes:

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

In this sample, it shows how to retrieve a String value with the key “name” from the document.

Image from Codeible.com

To get multiple values, chain multiple Get nodes together.

Image from Codeible.com

Attaching a listener to a document

You can also attach a listener to a document and listen to any changes made to it by using the “Listen To Document” node. This way, you’ll be able to update information in real-time every time data changes for a document.

Image from Codeible.com

It has the same 3 pin as the “Get Document” node. 

Document Path
On Document Retrieved Callback
On Fail to Retrieve Document Callback

The only difference is that the On Document Retrieved Callback gets called once at the beginning to get the contents of the document and then it’ll get called every time a change is made to the document.

Image from Codeible.com

Sign In