Ir a la consola

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

Index

Constructors

Private constructor

Properties

firestore

firestore: Firestore

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

id

id: string

The collection's identifier.

parent

parent: DocumentReference | null

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

path

path: string

A string representing the path of the referenced collection (relative to the root of the database).

Methods

add

  • add(data: DocumentData): Promise<DocumentReference>
  • Add a new document to this collection with the specified data, assigning it a document ID automatically.

    Parameters

    • data: DocumentData

      An Object containing the data for the new document.

    Returns Promise<DocumentReference>

    A Promise resolved with a DocumentReference pointing to the newly created document after it has been written to the backend.

doc

  • doc(documentPath?: string): DocumentReference
  • Get 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.

    Parameters

    • Optional documentPath: string

      A slash-separated path to a document.

    Returns DocumentReference

    The DocumentReference instance.

endAt

  • endAt(snapshot: DocumentSnapshot): Query
  • Creates and returns a new Query that ends 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.

    Parameters

    Returns Query

    The created Query.

  • endAt(...fieldValues: any[]): Query
  • Creates and returns a new Query that ends 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.

    Parameters

    • Rest ...fieldValues: any[]

      The field values to end this query at, in order of the query's order by.

    Returns Query

    The created Query.

endBefore

  • endBefore(snapshot: DocumentSnapshot): Query
  • Creates and returns a new Query that ends 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.

    Parameters

    Returns Query

    The created Query.

  • endBefore(...fieldValues: any[]): Query
  • Creates and returns a new Query that ends 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.

    Parameters

    • Rest ...fieldValues: any[]

      The field values to end this query before, in order of the query's order by.

    Returns Query

    The created Query.

get

  • get(options?: GetOptions): Promise<QuerySnapshot>
  • Executes the query and returns the results as a QuerySnapshot.

    Note: By default, get() attempts to provide up-to-date data when possible by waiting for data from the server, but it may return cached data or fail if you are offline and the server cannot be reached. This behavior can be altered via the GetOptions parameter.

    Parameters

    • Optional options: GetOptions

      An object to configure the get behavior.

    Returns Promise<QuerySnapshot>

    A Promise that will be resolved with the results of the Query.

isEqual

  • isEqual(other: CollectionReference): boolean
  • Returns true if this CollectionReference is equal to the provided one.

    Parameters

    Returns boolean

    true if this