The Firebase JS SDK is now in BETA!
This EAP site is no longer maintained. See the official Firebase Documentation site for the latest documentation and information about the Firebase JS SDK.

Home > @firebase/firestore > lite

@firebase/firestore/lite

Classes

Class Description
Bytes An immutable object representing an array of bytes.
CollectionReference A CollectionReference object can be used for adding documents, getting document references, and querying for documents (using query()).
DocumentReference A DocumentReference refers to a document location in a Firestore database and can be used to write, read, or listen to the location. The document at the referenced location may or may not exist.
DocumentSnapshot A DocumentSnapshot contains data read from a document in your Firestore database. The data can be extracted with .data() or .get(<field>) to get a specific field.For a DocumentSnapshot that points to a non-existing document, any data access will return 'undefined'. You can use the exists() method to explicitly verify a document's existence.
FieldPath A FieldPath refers to a field in a document. The path may consist of a single field name (referring to a top-level field in the document), or a list of field names (referring to a nested field in the document).Create a FieldPath by providing field names. If more than one field name is provided, the path will point to a nested field in a document.
FieldValue Sentinel values that can be used when writing document fields with set() or update().
FirebaseFirestore The Cloud Firestore service interface.Do not call this constructor directly. Instead, use getFirestore().
FirestoreError An error returned by a Firestore operation.
GeoPoint An immutable object representing a geographic location in Firestore. The location is represented as latitude/longitude pair.Latitude values are in the range of [-90, 90]. Longitude values are in the range of [-180, 180].
Query A Query refers to a Query which you can read or listen to. You can also construct refined Query objects by adding filters and ordering.
QueryConstraint A QueryConstraint is used to narrow the set of documents returned by a Firestore query. QueryConstraints are created by invoking where(), orderBy(), startAt(), startAfter(), , endAt(), limit() or limitToLast() and can then be passed to query() to create a new query instance that also contains this QueryConstraint.
QueryDocumentSnapshot A QueryDocumentSnapshot contains data read from a document in your Firestore database as part of a query. The document is guaranteed to exist and its data can be extracted with .data() or .get(<field>) to get a specific field.A QueryDocumentSnapshot offers the same API surface as a DocumentSnapshot. Since query results contain only existing documents, the exists property will always be true and data() will never return 'undefined'.
QuerySnapshot A QuerySnapshot contains zero or more DocumentSnapshot objects representing the results of a query. The documents can be accessed as an array via the docs property or enumerated using the forEach method. The number of documents can be determined via the empty and size properties.
Timestamp A Timestamp represents a point in time independent of any time zone or calendar, represented as seconds and fractions of seconds at nanosecond resolution in UTC Epoch time.It is encoded using the Proleptic Gregorian Calendar which extends the Gregorian calendar backwards to year one. It is encoded assuming all minutes are 60 seconds long, i.e. leap seconds are "smeared" so that no leap second table is needed for interpretation. Range is from 0001-01-01T00:00:00Z to 9999-12-31T23:59:59.999999999Z.For examples and further specifications, refer to the Timestamp definition.
Transaction A reference to a transaction.The Transaction object passed to a transaction's updateFunction provides the methods to read and write data within the transaction context. See runTransaction().
WriteBatch A write batch, used to perform multiple writes as a single atomic unit.A WriteBatch object can be acquired by calling writeBatch(). It provides methods for adding writes to the write batch. None of the writes will be committed (or visible locally) until WriteBatch.commit() is called.

Functions

Function Description
addDoc(reference, data) Add a new document to specified CollectionReference with the given data, assigning it a document ID automatically.The result of this write will only be reflected in document reads that occur after the returned Promise resolves. If the client is offline, the write fails. If you would like to see local modifications or buffer writes until the client is online, use the full Firestore SDK.
arrayRemove(elements) Returns a special value that can be used with setDoc() or that tells the server to remove the given elements from any array value that already exists on the server. All instances of each element specified will be removed from the array. If the field being modified is not already an array it will be overwritten with an empty array.
arrayUnion(elements) Returns a special value that can be used with setDoc() or updateDoc() that tells the server to union the given elements with any array value that already exists on the server. Each specified element that doesn't already exist in the array will be added to the end. If the field being modified is not already an array it will be overwritten with an array containing exactly the specified elements.
collection(firestore, path, pathSegments) Gets a CollectionReference instance that refers to the collection at the specified absolute path.
collection(reference, path, pathSegments) Gets a CollectionReference instance that refers to a subcollection of reference at the the specified relative path.
collection(reference, path, pathSegments) Gets a CollectionReference instance that refers to a subcollection of reference at the the specified relative path.
collectionGroup(firestore, collectionId) Creates and returns a new Query instance that includes all documents in the database that are contained in a collection or subcollection with the given collectionId.
deleteDoc(reference) Deletes the document referred to by the specified DocumentReference.The deletion will only be reflected in document reads that occur after the returned Promise resolves. If the client is offline, the delete fails. If you would like to see local modifications or buffer writes until the client is online, use the full Firestore SDK.
deleteField() Returns a sentinel for use with updateDoc() or setDoc() with {merge: true} to mark a field for deletion.
doc(firestore, path, pathSegments) Gets a DocumentReference instance that refers to the document at the specified abosulute path.
doc(reference, path, pathSegments) Gets a DocumentReference instance that refers to a document within reference at the specified relative path. If no path is specified, an automatically-generated unique ID will be used for the returned DocumentReference.
doc(reference, path, pathSegments) Gets a DocumentReference instance that refers to a document within reference at the specified relative path.
documentId() Returns a special sentinel FieldPath to refer to the ID of a document. It can be used in queries to sort or filter by the document ID.
endAt(snapshot) Creates a QueryConstraint that modifies the result set to end at the provided document (inclusive). The end position is relative to the order of the query. The document must contain all of the fields provided in the orderBy of the query.
endAt(fieldValues) Creates a QueryConstraint that modifies the result set to end at the provided fields relative to the order of the query. The order of the field values must match the order of the order by clauses of the query.
endBefore(snapshot) Creates a QueryConstraint that modifies the result set to end before the provided document (exclusive). The end position is relative to the order of the query. The document must contain all of the fields provided in the orderBy of the query.
endBefore(fieldValues) Creates a QueryConstraint that modifies the result set to end before the provided fields relative to the order of the query. The order of the field values must match the order of the order by clauses of the query.
getDoc(reference) Reads the document referred to by the specified document reference.All documents are directly fetched from the server, even if the document was previously read or modified. Recent modifications are only reflected in the retrieved DocumentSnapshot if they have already been applied by the backend. If the client is offline, the read fails. If you like to use caching or see local modifications, please use the full Firestore SDK.
getDocs(query) Executes the query and returns the results as a QuerySnapshot.All queries are executed directly by the server, even if the the query was previously executed. Recent modifications are only reflected in the retrieved results if they have already been applied by the backend. If the client is offline, the operation fails. To see previously cached result and local modifications, use the full Firestore SDK.
getFirestore(app) Returns the existing instance of Firestore that is associated with the provided FirebaseApp. If no instance exists, initializes a new instance with default settings.
increment(n) Returns a special value that can be used with setDoc() or updateDoc() that tells the server to increment the field's current value by the given value.If either the operand or the current field value uses floating point precision, all arithmetic follows IEEE 754 semantics. If both values are integers, values outside of JavaScript's safe number range (Number.MIN_SAFE_INTEGER to Number.MAX_SAFE_INTEGER) are also subject to precision loss. Furthermore, once processed by the Firestore backend, all integer operations are capped between -2^63 and 2^63-1.If the current field value is not of type number, or if the field does not yet exist, the transformation sets the field to the given value.
initializeFirestore(app, settings) Initializes a new instance of Cloud Firestore with the provided settings. Can only be called before any other functions, including getFirestore(). If the custom settings are empty, this function is equivalent to calling getFirestore().
limit(limit) Creates a QueryConstraint that only returns the first matching documents.
limitToLast(limit) Creates a QueryConstraint that only returns the last matching documents.You must specify at least one orderBy clause for limitToLast queries, otherwise an exception will be thrown during execution.
orderBy(fieldPath, directionStr) Creates a QueryConstraint that sorts the query result by the specified field, optionally in descending order instead of ascending.
query(query, queryConstraints) Creates a new immutable instance of Query that is extended to also include additional query constraints.
queryEqual(left, right) Returns true if the provided queries point to the same collection and apply the same constraints.
refEqual(left, right) Returns true if the provided references are equal.
runTransaction(firestore, updateFunction) Executes the given updateFunction and then attempts to commit the changes applied within the transaction. If any document read within the transaction has changed, Cloud Firestore retries the updateFunction. If it fails to commit after 5 attempts, the transaction fails.The maximum number of writes allowed in a single transaction is 500.
serverTimestamp() Returns a sentinel used with setDoc() or updateDoc() to include a server-generated timestamp in the written data.
setDoc(reference, data) Writes to the document referred to by the specified DocumentReference. If the document does not yet exist, it will be created.The result of this write will only be reflected in document reads that occur after the returned Promise resolves. If the client is offline, the write fails. If you would like to see local modifications or buffer writes until the client is online, use the full Firestore SDK.
setDoc(reference, data, options) Writes to the document referred to by the specified DocumentReference. If the document does not yet exist, it will be created. If you provide merge or mergeFields, the provided data can be merged into an existing document.The result of this write will only be reflected in document reads that occur after the returned Promise resolves. If the client is offline, the write fails. If you would like to see local modifications or buffer writes until the client is online, use the full Firestore SDK.
setLogLevel(logLevel) Sets the verbosity of Cloud Firestore logs (debug, error, or silent).
snapshotEqual(left, right) Returns true if the provided snapshots are equal.
startAfter(snapshot) Creates a QueryConstraint that modifies the result set to start after the provided document (exclusive). The starting position is relative to the order of the query. The document must contain all of the fields provided in the orderBy of the query.
startAfter(fieldValues) Creates a QueryConstraint that modifies the result set to start after the provided fields relative to the order of the query. The order of the field values must match the order of the order by clauses of the query.
startAt(snapshot) Creates a QueryConstraint that modifies the result set to start at the provided document (inclusive). The starting position is relative to the order of the query. The document must contain all of the fields provided in the orderBy of this query.
startAt(fieldValues) Creates a QueryConstraint that modifies the result set to start at the provided fields relative to the order of the query. The order of the field values must match the order of the order by clauses of the query.
terminate(firestore) Terminates the provided Firestore instance.After calling terminate() only the clearIndexedDbPersistence() functions may be used. Any other function will throw a FirestoreError. Termination does not cancel any pending writes, and any promises that are awaiting a response from the server will not be resolved.To restart after termination, create a new instance of FirebaseFirestore with getFirestore().Note: Under normal circumstances, calling terminate() is not required. This function is useful only when you want to force this instance to release all of its resources or in combination with clearIndexedDbPersistence() to ensure that all local state is destroyed between test runs.
updateDoc(reference, data) Updates fields in the document referred to by the specified DocumentReference. The update will fail if applied to a document that does not exist.The result of this update will only be reflected in document reads that occur after the returned Promise resolves. If the client is offline, the update fails. If you would like to see local modifications or buffer writes until the client is online, use the full Firestore SDK.
updateDoc(reference, field, value, moreFieldsAndValues) Updates fields in the document referred to by the specified DocumentReference The update will fail if applied to a document that does not exist.Nested fields can be updated by providing dot-separated field path strings or by providing FieldPath objects.The result of this update will only be reflected in document reads that occur after the returned Promise resolves. If the client is offline, the update fails. If you would like to see local modifications or buffer writes until the client is online, use the full Firestore SDK.
useFirestoreEmulator(firestore, host, port) Modify this instance to communicate with the Cloud Firestore emulator.Note: This must be called before this instance has been used to do any operations.
where(fieldPath, opStr, value) Creates a QueryConstraint that enforces that documents must contain the specified field and that the value should satisfy the relation constraint provided.
writeBatch(firestore) Creates a write batch, used for performing multiple writes as a single atomic operation. The maximum number of writes allowed in a single WriteBatch is 500.The result of these writes will only be reflected in document reads that occur after the returned Promise resolves. If the client is offline, the write fails. If you would like to see local modifications or buffer writes until the client is online, use the full Firestore SDK.

Interfaces

Interface Description
DocumentData Document data (for use with setDoc()) consists of fields mapped to values.
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.
Settings Specifies custom configurations for your Cloud Firestore instance. You must set these before invoking any other methods.
UpdateData Update data (for use with updateDoc()) consists of field paths (e.g. 'foo' or 'foo.baz') mapped to values. Fields that contain dots reference nested fields within the document.

Type Aliases

Type Alias Description
FirestoreErrorCode The set of Firestore status codes. The codes are the same at the ones exposed by gRPC here: https://github.com/grpc/grpc/blob/master/doc/statuscodesPossible values: - 'cancelled': The operation was cancelled (typically by the caller). - 'unknown': Unknown error or an error from a different error domain. - 'invalid-argument': Client specified an invalid argument. Note that this differs from 'failed-precondition'. 'invalid-argument' indicates arguments that are problematic regardless of the state of the system (e.g. an invalid field name). - 'deadline-exceeded': Deadline expired before operation could complete. For operations that change the state of the system, this error may be returned even if the operation has completed successfully. For example, a successful response from a server could have been delayed long enough for the deadline to expire. - 'not-found': Some requested document was not found. - 'already-exists': Some document that we attempted to create already exists. - 'permission-denied': The caller does not have permission to execute the specified operation. - 'resource-exhausted': Some resource has been exhausted, perhaps a per-user quota, or perhaps the entire file system is out of space. - 'failed-precondition': Operation was rejected because the system is not in a state required for the operation's execution. - 'aborted': The operation was aborted, typically due to a concurrency issue like transaction aborts, etc. - 'out-of-range': Operation was attempted past the valid range. - 'unimplemented': Operation is not implemented or not supported/enabled. - 'internal': Internal errors. Means some invariants expected by underlying system has been broken. If you see one of these errors, something is very broken. - 'unavailable': The service is currently unavailable. This is most likely a transient condition and may be corrected by retrying with a backoff. - 'data-loss': Unrecoverable data loss or corruption. - 'unauthenticated': The request does not have valid authentication credentials for the operation.
OrderByDirection The direction of a orderBy() clause is specified as 'desc' or 'asc' (descending or ascending).
QueryConstraintType Describes the different query constraints available in this SDK.
SetOptions An options object that configures the behavior of setDoc(), and calls. These calls can be configured to perform granular merges instead of overwriting the target documents in their entirety by providing a SetOptions with merge: true.
WhereFilterOp Filter conditions in a where() clause are specified using the strings '&lt;', '&lt;=', '==', '!=', '&gt;=', '&gt;', 'array-contains', 'in', 'array-contains-any', and 'not-in'.