Global

Members

WATCH_IDLE_TIMEOUT_MS

Idle timeout used to detect Watch streams that stall (see https://github.com/googleapis/nodejs-firestore/issues/1057, b/156308554). Under normal load, the Watch backend will send a TARGET_CHANGE message roughly every 30 seconds. As discussed with the backend team, we reset the Watch stream if we do not receive any message within 120 seconds.

Methods

getRetryCodes()

Returns the list of retryable error codes specified in the service configuration.

getRetryParams()

Returns the backoff setting from the service configuration.

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

DocumentData :Object.<string, *>

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 :Object

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
}

Precondition :Object

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 :Object

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 :Object

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 :Object.<string, *>

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.