Global

Members

(constant) gapicConfig

Client JSON configuration object, loaded from src/v1/firestore_client_config.json. This file defines retry strategy and timeouts for all API methods in this library.

(constant) gapicConfig

Client JSON configuration object, loaded from src/v1beta1/firestore_client_config.json. This file defines retry strategy and timeouts for all API methods in this library.

(constant) gapicConfig

Client JSON configuration object, loaded from src/v1/firestore_admin_client_config.json. This file defines retry strategy and timeouts for all API methods in this library.

Methods

setLogFunction(logger)

Sets or disables the log function for all active Firestore instances.

Parameters:
Name Type Description
logger

A log function that takes a message (such as console.log) or null to turn off logging.

Type Definitions

BulkWriterOptions

An options object to configure throttling on BulkWriter.

Whether to disable or configure throttling. By default, throttling is enabled. throttling can be set to either a boolean or a config object. Setting it to true will use default values. You can override the defaults by setting it to false to disable throttling, or by setting the config values to enable throttling with the provided values.

Properties:
Name Type Description
throttling boolean | Object

Whether to disable or enable throttling. Throttling is enabled by default, if the field is set to true or if any custom throttling options are provided. { initialOpsPerSecond: number } sets the initial maximum number of operations per second allowed by the throttler. If initialOpsPerSecond is not set, the default is 500 operations per second. { maxOpsPerSecond: number } sets the maximum number of operations per second allowed by the throttler. If maxOpsPerSecond is not set, no maximum is enforced.

DocumentData

Document data (e.g. for use with set()) consisting of fields mapped to values.

documentSnapshotCallback(snapshot)

onSnapshot() callback that receives a DocumentSnapshot.

Parameters:
Name Type Description
snapshot DocumentSnapshot

A document snapshot.

errorCallback(err)

onSnapshot() callback that receives an error.

Parameters:
Name Type Description
err Error

An error from a listen.

FirestoreDataConverter

Converter used by withConverter() to transform user objects of type T into Firestore data.

Using the converter allows you to specify generic type arguments when storing and retrieving objects from Firestore.

Properties:
Name Type Description
toFirestore function

Called by the Firestore SDK to convert a custom model object of type T into a plain Javascript object (suitable for writing directly to the Firestore database).

fromFirestore function

Called by the Firestore SDK to convert Firestore data into an object of type T.

Example
class Post {
  constructor(readonly title: string, readonly author: string) {}

  toString(): string {
    return this.title + ', by ' + this.author;
  }
}

const postConverter = {
  toFirestore(post: Post): FirebaseFirestore.DocumentData {
    return {title: post.title, author: post.author};
  },
  fromFirestore(
    data: FirebaseFirestore.QueryDocumentSnapshot
  ): Post {
    const data = snapshot.data();
    return new Post(data.title, data.author);
  }
};

const postSnap = await Firestore()
  .collection('posts')
  .withConverter(postConverter)
  .doc().get();
const post = postSnap.data();
if (post !== undefined) {
  post.title; // string
  post.toString(); // Should be defined
  post.someNonExistentProperty; // TS error
}

GrpcStatus

Status codes returned by GRPC operations.

See:

Precondition

An options object that configures conditional behavior of update() and delete() calls in DocumentReference, WriteBatch, and Transaction. Using Preconditions, these calls can be restricted to only apply to documents that match the specified conditions.

Properties:
Name Type Description
lastUpdateTime Timestamp

The update time to enforce. If set, enforces that the document was last updated at lastUpdateTime. Fails the operation if the document was last updated at a different time.

Example
const documentRef = firestore.doc('coll/doc');

documentRef.get().then(snapshot => {
  const updateTime = snapshot.updateTime;

  console.log(`Deleting document at update time: ${updateTime.toDate()}`);
  return documentRef.delete({ lastUpdateTime: updateTime });
});

querySnapshotCallback(snapshot)

onSnapshot() callback that receives a QuerySnapshot.

Parameters:
Name Type Description
snapshot QuerySnapshot

A query snapshot.

ReadOptions

An options object that can be used to configure the behavior of getAll() calls. By providing a fieldMask, these calls can be configured to only return a subset of fields.

Properties:
Name Type Description
fieldMask Array.<(string|FieldPath)>

Specifies the set of fields to return and reduces the amount of data transmitted by the backend. Adding a field mask does not filter results. Documents do not need to contain values for all the fields in the mask to be part of the result set.

SetOptions

An options object that configures the behavior of set() calls in DocumentReference, WriteBatch, and Transaction. These calls can be configured to perform granular merges instead of overwriting the target documents in their entirety by providing a SetOptions object with { merge : true }.

Properties:
Name Type Description
merge boolean

Changes the behavior of a set() call to only replace the values specified in its data argument. Fields omitted from the set() call remain untouched.

mergeFields Array.<(string|FieldPath)>

Changes the behavior of set() calls to only replace the specified field paths. Any field path that is not specified is ignored and remains untouched. It is an error to pass a SetOptions object to a set() call that is missing a value for any of the fields specified here.

UpdateData

Update data (for use with update) that contains paths (e.g. 'foo' or 'foo.baz') mapped to values. Fields that contain dots reference nested fields within the document.