Created
July 1, 2020 00:46
-
-
Save agmm/90358d7661ac962a5b2eef692352c3d9 to your computer and use it in GitHub Desktop.
Firestore Admin NodeJS
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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