How to use the firebase-admin.firestore function in firebase-admin

To help you get started, we’ve selected a few firebase-admin examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github andrewevans0102 / how-to-build-a-firebase-api / functions / index.js View on Github external
const functions = require('firebase-functions');
const admin = require('firebase-admin');
const express = require('express');
const cors = require('cors');
const app = express();
app.use(cors({ origin: true }));

var serviceAccount = require("./permissions.json");
admin.initializeApp({
  credential: admin.credential.cert(serviceAccount),
  databaseURL: "https://fir-api-9a206.firebaseio.com"
});
const db = admin.firestore();

// create
app.post('/api/create', (req, res) => {
    (async () => {
        try {
            await db.collection('items').doc('/' + req.body.id + '/').create({item: req.body.item});
            return res.status(200).send();
        } catch (error) {
            console.log(error);
            return res.status(500).send(error);
        }
      })();
  });

// read item
app.get('/api/read/:item_id', (req, res) => {
github moflo / jpvcdb / src / app / scripts / add-airtable-records.js View on Github external
const admin = require('firebase-admin')
const chalk = require('chalk')
var Airtable = require('airtable');


// init firebase
const serviceAccount = require('../credentials/serviceAccountKey.json')
admin.initializeApp({
  credential: admin.credential.cert(serviceAccount),
  databaseURL: "https://jpvcdb.firebaseio.com"
})
const db = require('firebase-admin').firestore()
db.settings({timestampsInSnapshots: true})  // Using Timestamps

const airTableAccount = require('../credentials/airTableKey.json')
var base = new Airtable({apiKey: airTableAccount.apiKey}).base(airTableAccount.appKey);

// add seed posts
console.log(chalk.blue(`Adding seed post data...`))

base('Table 2').select({
    // Selecting the first 3 records in Grid view:
    // maxRecords: 3,
    pageSize: 10,
    view: "Grid view",
    cellFormat: 'json'
}).eachPage(function page(records, fetchNextPage) {
    // This function (`page`) will get called for each page of records.
github Kesin11 / Firestore-simple / test / util.ts View on Github external
export const initFirestore = () => {
  admin.initializeApp({
    credential: admin.credential.cert(serviceAccount),
  })
  return admin.firestore()
}
github oddbit / tanam / functions / src / services / site-info.service.ts View on Github external
const defaultDomains = [`${process.env.GCLOUD_PROJECT}.firebaseapp.com`, `${process.env.GCLOUD_PROJECT}.web.app`];
    console.log(`[createDefaultSiteInfo] ${defaultDomains}`);

    const siteInfoData: SiteInformation = {
        id: siteId,
        defaultLanguage: 'en',
        languages: ['en'],
        isCustomDomain: false,
        domains: defaultDomains,
        primaryDomain: defaultDomains[0],
        analytics: '',
        theme: 'default',
        title: process.env.GCLOUD_PROJECT
    };

    return admin.firestore().collection('tanam').doc(siteId).set(siteInfoData);
}
github samuraikun / firebase-youtube-clone / functions / transcodeVideo.js View on Github external
const fs = require('fs');
const ffmpeg = require('fluent-ffmpeg');
const ffmpeg_static = require('ffmpeg-static');
const UUID = require('uuid-v4');
const serviceAccount = require('./config/service_account.json');

const {Storage} = require('@google-cloud/storage');
const gcs = new Storage({keyFilename: './config/service_account.json'});

const admin = require('firebase-admin');
try {
  admin.initializeApp({
    credential: admin.credential.cert(serviceAccount),
    databaseURL: "https://fir-reacty-videos.firebaseio.com"
  });
  admin.firestore().settings({timestampsInSnapshots: true});
} catch (error) {
  console.log(error);
}

function promisifyCommand(command) {
  return new Promise((resolve, reject) => {
    command.on('end', resolve).on('error', reject).run();
  });
}

async function saveVideoMetadata(userToken, metadata) {
  const decodedToken = await admin.auth().verifyIdToken(userToken);
  const user_id = decodedToken.uid;
  const videoRef = admin.firestore().doc(`users/${user_id}`).collection('videos').doc();
  metadata = Object.assign(metadata, { uid: videoRef.id });
github felipepastorelima / react-pet-hotel / 1-Project / backend-firestore / src / database / repositories / abstractEntityRepository.js View on Github external
async function removeRelationOldTargets() {
      const targetCollection = await admin
        .firestore()
        .collection(targetCollectionName)
        .where(targetProperty, 'array-contains', record.id)
        .get();

      const promises = targetCollection.docs.map(
        async (doc) => {
          if (doc.id === record[sourceProperty]) {
            return;
          }

          await AbstractEntityRepository.executeOrAddToBatch(
            'update',
            doc.ref,
            {
              [targetProperty]: admin.firestore.FieldValue.arrayRemove(
github firebase / firebase-functions / src / providers / firestore.ts View on Github external
export function snapshotConstructor(event: Event): DocumentSnapshot {
  if (!firestoreInstance) {
    firestoreInstance = firebase.firestore(apps().admin);
  }
  const valueProto = _getValueProto(
    event.data,
    event.context.resource.name,
    'value'
  );
  const readTime = dateToTimestampProto(_.get(event, 'data.value.readTime'));
  return firestoreInstance.snapshot_(valueProto, readTime, 'json');
}
github fireship-io / 202-chatbot-dialogflow / functions / index.js View on Github external
async function userOnboardingHandler(agent) {

     const db = admin.firestore();
     const profile = db.collection('users').doc('jeffd23');

     const { name, color } = result.parameters;

      await profile.set({ name, color })
      agent.add(`Welcome aboard my friend!`);
    }