Skip to content

Instantly share code, notes, and snippets.

@agmm
Created July 1, 2020 00:46
Show Gist options
  • Save agmm/90358d7661ac962a5b2eef692352c3d9 to your computer and use it in GitHub Desktop.
Save agmm/90358d7661ac962a5b2eef692352c3d9 to your computer and use it in GitHub Desktop.
Firestore Admin NodeJS
const { Firestore } = require('@google-cloud/firestore');
// Create a new client
const firestore = new Firestore({ projectId: id, keyFilename: pathToServiceAccountJsonKey });
async function quickstart() {
// Obtain a document reference.
const document = firestore.doc('posts/intro-to-firestore');
// Enter new data into the document.
await document.set({
title: 'Welcome to Firestore',
body: 'Hello World',
});
console.log('Entered new data into the document');
// Update an existing document.
await document.update({
body: 'My first Firestore app',
});
console.log('Updated an existing document');
// Read the document.
const doc = await document.get();
console.log('Read the document');
// Delete the document.
await document.delete();
console.log('Deleted the document');
}
quickstart();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment