Skip to content

Firestore Method Documentation

Graham Earley edited this page Apr 28, 2018 · 11 revisions

To get an instance of the Firestore object for your project from this library, call

var firestore = FirestoreApp.getFirestore(email, key, projectId);

This page documents the methods that belong to the Firestore object (referred to with firestore).

Updating / Writing to Firestore

firestore.createDocumentWithId(documentId, path, fields)

Create a document with the given ID and fields.

Returns: the Document object written to Firestore

Parameter name Type Description
documentId string the ID of the document in Firestore
path string the path where the document will be written
fields object the document's fields as a JSON object

firestore.createDocument(path, fields)

Create a document with the given fields and an auto-generated ID.

Returns: the Document object written to Firestore

Parameter name Type Description
path string the path where the document will be written
fields object the document's fields as a JSON object

firestore.updateDocument(path, fields)

Update/patch a document at the given path with new fields.

Returns: the Document object written to Firestore

Parameter name Type Description
path string the path of the document to update
fields object the new fields to write to the document

firestore.deleteDocument(pathToDocument)

Delete the Firestore document at the given path. Note: this deletes ONLY this document, and not any subcollections.

Returns: the JSON response from the DELETE request.

Parameter name Type Description
pathToDocument string the path of the document to delete

Reading from Firestore

firestore.getDocument(path)

Get a document.

Returns: a document object.

Parameter name Type Description
path string the path to the document

firestore.getDocuments(pathToCollection)

Get a list of all documents in a collection.

Returns: an array of the documents in the collection

Parameter name Type Description
pathToCollection string the path to the collection

firestore.getDocumentIds(pathToCollection)

Get a list of all IDs of the documents in a collection.

Returns: an array of IDs of the documents in the collection

Parameter name Type Description
pathToCollection string the path to the collection
Clone this wiki locally