Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@google-cloud/firestore

Package Overview
Dependencies
Maintainers
4
Versions
146
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@google-cloud/firestore

Firestore Client Library for Node.js

  • 1.0.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
1.9M
decreased by-3.8%
Maintainers
4
Weekly downloads
 
Created

What is @google-cloud/firestore?

The @google-cloud/firestore npm package is a client library for accessing Google Cloud Firestore, a NoSQL document database built for automatic scaling, high performance, and ease of application development. It provides functionality to perform various operations such as adding, updating, deleting documents, querying collections, and managing transactions.

What are @google-cloud/firestore's main functionalities?

Adding Documents

This code sample demonstrates how to add a document to a Firestore collection. It creates a new document with a specified ID ('alovelace') and sets the data for the document.

const { Firestore } = require('@google-cloud/firestore');
const firestore = new Firestore();
const document = firestore.collection('users').doc('alovelace');
document.set({
  first: 'Ada',
  last: 'Lovelace',
  born: 1815
});

Updating Documents

This code sample shows how to update an existing document in a Firestore collection. It updates the 'born' field of the document with the ID 'alovelace'.

const { Firestore } = require('@google-cloud/firestore');
const firestore = new Firestore();
const document = firestore.collection('users').doc('alovelace');
document.update({
  born: 1816
});

Deleting Documents

This code sample illustrates how to delete a document from a Firestore collection. It deletes the document with the ID 'alovelace'.

const { Firestore } = require('@google-cloud/firestore');
const firestore = new Firestore();
const document = firestore.collection('users').doc('alovelace');
document.delete();

Querying Collections

This code sample demonstrates how to query documents in a Firestore collection that meet certain criteria. It retrieves all documents where the 'born' field is greater than 1800.

const { Firestore } = require('@google-cloud/firestore');
const firestore = new Firestore();
firestore.collection('users').where('born', '>', 1800).get()
  .then(snapshot => {
    snapshot.forEach(doc => console.log(doc.id, '=>', doc.data()));
  });

Managing Transactions

This code sample shows how to use transactions to read and write data atomically. It reads a document and then updates it within a transaction, ensuring that the operation is atomic.

const { Firestore } = require('@google-cloud/firestore');
const firestore = new Firestore();
let documentRef = firestore.collection('users').doc('alovelace');
firestore.runTransaction(transaction => {
  return transaction.get(documentRef).then(doc => {
    if (!doc.exists) {
      throw 'Document does not exist!';
    }
    let newBorn = doc.data().born + 1;
    transaction.update(documentRef, { born: newBorn });
  });
}).then(() => console.log('Transaction successfully committed!'))
.catch(error => console.log('Transaction failed: ', error));

Other packages similar to @google-cloud/firestore

Keywords

FAQs

Package last updated on 29 Jan 2019

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc