Constructor

CollectionReference

new CollectionReference()

A CollectionReference object can be used for adding documents, getting document references, and querying for documents (using the methods inherited from Query).

Extends
firebase.firestore.Query

Properties

firestore

unknown

The Firestore for the Cloud Firestore database (useful for performing transactions, etc.).

Inherited from
firebase.firestore.Query#firestore

id

string

The collection's identifier.

parent

nullable firebase.firestore.DocumentReference

A reference to the containing DocumentReference if this is a subcollection. If this isn't a subcollection, the reference is null.

Methods

add

add(data) returns Promise containing non-null firebase.firestore.DocumentReference

Adds a new document to this collection with the specified data, assigning it a document ID automatically.

Parameter

data

firebase.firestore.Firestore~DocumentData

Value must not be null.

Returns

non-null Promise containing non-null firebase.firestore.DocumentReference A Promise that resolves with a DocumentReference pointing to the newly created document after it has been written to the backend.

doc

doc(documentPath) returns firebase.firestore.DocumentReference

Gets a DocumentReference for the document within the collection at the specified path. If no path is specified, an automatically-generated unique ID will be used for the returned DocumentReference.

Parameter

documentPath

Optional

string

A slash-separated path to a document.

Returns

non-null firebase.firestore.DocumentReference 

endAt

endAt(snapshotOrVarArgs) returns firebase.firestore.Query

Creates a new query where the results 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 this query.

Parameter

snapshotOrVarArgs

The snapshot of the document the query results should end at or the field values to end this query at, in order of the query's order by.

Inherited from
firebase.firestore.Query#endAt
Returns

The created query.

endBefore

endBefore(snapshotOrVarArgs) returns firebase.firestore.Query

Creates a new query where the results 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 this query.

Parameter

snapshotOrVarArgs

The snapshot of the document the query results should end before or the field values to end this query before, in order of the query's order by.

Inherited from
firebase.firestore.Query#endBefore
Returns

The created query.

get

get() returns firebase.firestore.QuerySnapshot

Executes the query and returns the results as a QuerySnapshot.

Inherited from
firebase.firestore.Query#get
Returns

A promise that will be resolved with the results of the query.

isEqual

isEqual(other) returns boolean

Returns 'true' if this CollectionReference is equal to the provided one.

Parameter

other

firebase.firestore.CollectionReference

The CollectionReference to compare against.

Value must not be null.

Returns

boolean 'true' if this CollectionReference is equal to the provided one.

limit

limit(limit) returns firebase.firestore.Query

Creates a new query where the results are limited to the specified number of documents.

Parameter

limit

The maximum number of items to return.

Inherited from
firebase.firestore.Query#limit
Returns

The created query.

onSnapshot

onSnapshot(optionsOrObserverOrOnNext, observerOrOnNextOrOnError, onError, onCompletion) returns function()

Attaches a listener for QuerySnapshot events. You may either pass individual onNext and onError callbacks or pass a single observer object with next and error callbacks. The listener can be cancelled by calling the function that is returned when onSnapshot is called.

NOTE: Although an onCompletion callback can be provided, it will never be called because the snapshot stream is never-ending.

Parameter

optionsOrObserverOrOnNext

This can be an observer object or an onNext function callback. It can also be an options object containing { includeMetadataChanges: true } to opt into events even when only metadata changed.

observerOrOnNextOrOnError

If you provided options, this will be an observer object or your onNext callback. Else, it is an optional onError callback.

onError

Optional

If you didn't provide options and didn't use an observer object, this is the optional onError callback.

onCompletion

Value must not be null.

Inherited from
firebase.firestore.Query#onSnapshot
Returns

An unsubscribe function that can be called to cancel the snapshot listener.

orderBy

orderBy(fieldPath, directionStr) returns firebase.firestore.Query

Creates a new query where the results are sorted by the specified field, in descendin or ascending order.

Parameter

fieldPath

The field to sort by.

directionStr

Optional

Optional direction to sort by (asc or desc). If not specified, the default order is ascending.

Inherited from
firebase.firestore.Query#orderBy
Returns

The created query.

startAfter

startAfter(snapshotOrVarArgs) returns firebase.firestore.Query

Creates a new query where the results 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 this query.

Parameter

snapshotOrVarArgs

The snapshot of the document to start after or the field values to start this query after, in order of the query's order by.

Inherited from
firebase.firestore.Query#startAfter
Returns

The created query.

startAt

startAt(snapshotOrVarArgs) returns firebase.firestore.Query

Creates a new query where the results 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 the query.

Parameter

snapshotOrVarArgs

The snapshot of the document you want the query to start at or the field values to start this query at, in order of the query's order by.

Inherited from
firebase.firestore.Query#startAt
Returns

The created query.

where

where(fieldPath, opStr, value) returns firebase.firestore.Query

Creates a new query that returns only documents that include the specified fields and where the values satisfy the constraints provided.

Parameter

fieldPath

The path to compare.

opStr

The operation string (e.g "<", "<=", "==", ">", ">=").

value

The value for comparison.

Inherited from
firebase.firestore.Query#where
Returns

The created query.