πŸ”₯ Firestore: scalable database

1.Introduction

Extension Name: Firestore
Cloud Firestore is Firebase's newest database for mobile app development. It builds on the successes of the Realtime Database with a new, more intuitive data model. Cloud Firestore also features richer, faster queries and scales further than the Realtime Database.

Latest Version: 1.0
Released: 2020-07-12T04:37:00Z
Last Updated: 2020-07-12T04:37:00Z

2.Documentation

Methods

β€’ Initialize Firebase
Initializes the SDK.
image
Activate the firestore in your Firebase, in the rules, activate the reading and writing. In your project's settings in firebase, go to add application, select web, put a nickname and copy the following data:

"projectId" ➜ projectId;
"appId" ➜ aplicationId;
"apiKey" ➜ apiKey.
persistent ~ boolean

Rules
Remember to change your rules in the firestore, in this example it allows you to read and write to your database.
image

β€’ Get Document Query
Get a list of documents according to the query, returning it in "GotQuery".
image
collectionReference ~ text
query ~ list

Key: queryType, Value:

β€’ limit ~ text
Key: value, Value: (Limit of documents returned ~ number)
image

β€’ where ~ text
Key: value, Value: ~ dictonary

  1. Key: fieldpath, Value: ~ text
  2. Key: opStr, Value: (β€œ==”,”>”,”>=”,”<”,”<=”)
  3. Key: value, Value: (value to be compared)
    image

β€’ orderBy ~ text
Key: value, Value: ~ dictonary

  1. Key: direction, Value: (β€œasc”, β€œdesc”)
  2. Key: field, Value: ~ text
    image

β€’ startAfter ~ text
Key: value, Value: (Start after that value)
image

β€’ startAt ~ text
Key: value, Value: (Start at that value)
image

β€’ endAt ~ text
*Key: value, Value: (end at that value)
image
β€’ endBefore ~ text
Key: value, Value: (end before that value)
image

Example

In this example, all documents in the reference collection are left in ascending order relative to the "id" of the field and then a limit of 5 is placed.


Note: As we can see, the order of selection is from bottom to top in the list :arrow_up:.

β€’ Set Document
Set the documents
image
documentReference ~ text
document ~ dictionary

β€’ Set Field With Merge
Update one field, creating the document if it does not already exist.
image
documentReference ~ text
document ~ dictionary

β€’ Add Document
Add a new document with a generated id.
image
collectionReference ~ text
document ~ dictionary

β€’ New Document
Create a new empty document with a specific name, if you want to create it by generating an id leave the documentName field empty.
image
collectionReference ~ text
documentName ~ text

β€’ Updates Document
Updates the document.
image
collectionReference ~ text
document ~ dictionary

β€’ Get All Docs
Gets the complete list of documents in the collection, returning to GotAllDocs.
image
collectionReference ~ text

β€’ Register Listener
Register a listener and if there are changes to the collection it will return to OnListenerAdded, OnListenerModified, OnListenerRemoved.
image
collectionRefernce ~ text

β€’ Remove Listener
Removes the listener.
image
collectionRefernce ~ text

β€’ Delete Collection
Deleted collection.
image
collectionReference ~ text

β€’ Delete Document
Deleted document.
image
documentReference ~ text

Events

β€’ Got All Docs
Event returns all documents.
image
documents ~ list

β€’ Got Query
Event returns a list with the selected data.
image
documents ~ list

β€’ On Success
Returns the event if any method is successful.
image
message ~ text

β€’ On Failure
Returns the error message.
image
message ~ text

β€’ On Listener Added
When registering the listener, this event will be called when adding a field to the collection.
image
document ~ dictionary

β€’ On Listener Modified
When registering the listener, this event will be called when modifying a field in the collection.
image
document ~ dictionary

β€’ On Listener Removed
When registering the listener, this event will be called when removing a field from the collection.
image
document ~ dictionary

3.Downloads

Aix file: com.jdl.Firestore.aix (2.5 MB)

Aia file: Firestore_MIT.aia (2.5 MB)

4.Open Source

5.Credits

Thank you very much App Inventor, for being part of my life :heart:

6.Donate

If you liked my work, donate me any amount so that I can remain motivated to create free and open source extensions.
https://www.paypal.com/cgi-bin/webscr?cmd=_donations&business=QJ76K7BA7KD3A&currency_code=USD&source=url

18 Likes

(added to FAQ)

4 Likes

Version 1.1

Guide

6 Likes

Please help;
um trying to read data from the firestore,now um getting an error " Invalid document reference. Document references must have an even number of segments, but --- has 1".

I could quote more details, blocks, structure of the database.

how do i create document reference?
my database is called "portal",collection "number plate" and the added document is "71679"..

1 Like

this what basically my app should do,it has to read and display documents data from the firestore on the screen.Um stuck,can i share my .aia so you look into it? :grin:

1 Like

To reference a document, just use this structure: collection/document.

Example:


To obtain the document Brazil, just use this block.
blocks - 2020-07-25T212140.235

If it doesn't work, you can send me the .aia that I will check.

project1_BEch.aia (2.8 MB) i have managed to eliminate the error,now its returning "null" instead of the results..please check if my syntax is correct on Screen 5

2 Likes

i have managed to read from firestore,now um getting this error "Lookup in pairs: the list ["Reg", "15000350"] is not a well-formed list of pairs" error..please help

1 Like

Could you send a picture of the new blocks you added? I saw your project and it was in syntax error. I also have to know what you want to do on screen 5.

i want it to get the input from the user which is the number plate,then use the manual input to retrieve the data from the database and display it on a Label.

1 Like

In GetDocument, document is a dictionary, not a list.


Remembering that in some fields you use :

i dont understand,should i replace getdocument with a dictionary like in picture?

You need to remove the for each block. Check the blocks you send in the message above. Here it worked perfectly.

i managed to get the results sir,thank you very much :relaxed:..how can i remove "" on the string and arrange them vertically?

i have met maximum number of replies now

1 Like

or should i send the .aia?

1 Like

Try to do that.

Screen 4

Screen 8

blocks - 2020-07-26T140501.700

As a result you will achieve this.

Doing the most basic request: Initialise -> Get -> When -> set text to get document.

Gives me

"Runtime Error"
"Failed resolution of Landroid/support/v4/util/ArrayMap;"

Any support greatly appreciated.

1 Like