-
Notifications
You must be signed in to change notification settings - Fork 86
Firestore
Note you need to be authenticated for this to work
Firebase.Firestore.collection('COLLECTION_NAME')
The following will return a collection from Firestore called firestore_collection
. This collection can be called on later when adding or getting documents from it.
firestore_collection = Firebase.Firestore.collection('COLLECTION_NAME')
Note you need to be authenticated and connected to a collection for this to work
.get(documentId : String)
The following will return a document from Firestore with the DOCUMENT_ID
that is specified to an object called firestore_document
.
firestore_document = firestore_collection.get('DOCUMENT_ID')
The following will parse the data into a human readable format by using the function fields2dict
print(firestore_document.fields2dict(firestore_document.document))
Note you need to be authenticated and connected to a collection for this to work
.add(documentId : String, fields : Dictionary = {})
The following will add a new document into Firestore by first creating the object, and then adding it. The function dict2fields
is used to convert the dictionary of fields into the correct format for Firestore to use.
firestore_document : FirestoreDocument = FirestoreDocument.new()
firestore_collection.add("DOCUMENT_ID", firestore_document.dict2fields({'name': 'Document Name', 'active': 'true'}))
Note you need to be authenticated and connected to a collection for this to work
There are some signals that can be connected to for the purpose of debugging
- Signal ("add_document", document )
- Signal ("get_document", document )
- Signal ("update_document", document )
- Signal ("delete_document")
- Signal ("error",bod.error.code,bod.error.status,bod.error.message)
These signals need to be connected to from the collection
firestore_collection.connect("add_document", self, "on_document_add")
firestore_collection.connect("get_document", self, "on_document_get")
firestore_collection.connect("update_document", self, "on_document_update")
firestore_collection.connect("delete_document", self, "on_document_delete")
firestore_collection.connect("error", self, "on_document_error")
This occurs when you are trying to do something with a collection but have not logged in