Code Monkey home page Code Monkey logo

firestoregoogleappsscript's Introduction

Firestore for Google Apps Scripts

A Google Apps Script library for accessing Google Cloud Firestore.

This library allows a user (or service account) to authenticate with Firestore and edit their Firestore database within a Google Apps Script.

Read how this project was started here.

Installation

In the Google online script editor, select the Resources menu item and choose Libraries.... In the "Add a library" input box, enter MX2_NUfxVpaA1XPcZ_N-3wWb_Hp7BVbw3 and click "Add." Choose the most recent version number.

Quick start with a service account

Follow these instructions (just the "Creating a service account" section) to obtain a service account email address and private key. Ensure you have given the account full read/write access to the https://www.googleapis.com/auth/datastore scope.

Now, with your service account email address email and private key key, we will create a document with a field name with value test!. You will need your project ID to do this (we'll assume you've stored the ID in a variable called projectId).

We encode these fields as a JSON object:

const data = {
  "name": "test!"
}

Now, we can create a document called FirstDocument at a collection called "FirstCollection":

FirestoreApp.createDocumentWithId("FirstCollection", "FirstDocument", data, email, key, projectId)

To update the document at this location, we can use the updateDocument function:

FirestoreApp.updateDocument("FirstCollection/FirstDocument", data, email, key, projectId)

Note: Although you can call updateDocument without using createDocument to create the document, any documents in your path will not be created and thus you can only access the document by using the path explicitly.

Contributions

Contributions are welcome -- send a pull request! This library is a work in progress and currently only supports creating and updating documents with fields (whose values are strings, numbers, booleans, arrays, or objects).

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.