Node.js

Initialize

Install Berlioz SDK:

$ npm install --save berlioz-sdk berlioz-gcp

Include Berlioz SDK:

const berlioz = require('berlioz-sdk');
berlioz.addon(require('berlioz-gcp'));

Accessing Firestore

berlioz.database('<firestore-name>').client('firestore')

Wraps GCP Firestore SDK and return instance of Firestore. All operations return Promise.

Examples

Listing Documents

var client = berlioz.database('store').client('firestore');
client.collection('users').listDocuments()
    .then(documentRefs => {
        return firestore.getAll(documentRefs);
    })
    .then(documentSnapshots => {
        documentSnapshots = documentSnapshots.filter(x => x.exists);
        var datas = documentSnapshots.map(x => x.data());
        return datas;
    })

Creating Document

var client = berlioz.database('store').client('firestore');
client.doc('users/chuck').set({
    first: 'chuck',
    last: 'norris'
})

Fetching Document

var client = berlioz.database('store').client('firestore');
client.doc('users/chuck')
    .get()
    .then(documentSnapshot => {
        if (documentSnapshot.exists) {
            console.log(documentSnapshot.data())
        } else {
            console.log('Not Present')
        }
    })