FIRCollectionReference


@interface FIRCollectionReference : FIRQuery

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

  • Declaration

    Objective-C

    - (nonnull id)init;
  • ID of the referenced collection.

    Declaration

    Swift

    var collectionID: String { get }

    Objective-C

    @property (readonly, strong, nonatomic) NSString *_Nonnull collectionID;
  • For subcollections, parent returns the containing FIRDocumentReference. For root collections, nil is returned.

    Declaration

    Swift

    var parent: FIRDocumentReference? { get }

    Objective-C

    @property (readonly, strong, nonatomic, nullable) FIRDocumentReference *parent;
  • A string containing the slash-separated path to this this FIRCollectionReference (relative to the root of the database).

    Declaration

    Swift

    var path: String { get }

    Objective-C

    @property (readonly, strong, nonatomic) NSString *_Nonnull path;
  • Returns a FIRDocumentReference pointing to a new document with an auto-generated ID.

    Declaration

    Swift

    func document() -> FIRDocumentReference

    Objective-C

    - (nonnull FIRDocumentReference *)documentWithAutoID;

    Return Value

    A FIRDocumentReference pointing to a new document with an auto-generated ID.

  • Gets a FIRDocumentReference referring to the document at the specified path, relative to this collection’s own path.

    Declaration

    Swift

    func document(_ documentPath: String) -> FIRDocumentReference

    Objective-C

    - (nonnull FIRDocumentReference *)documentWithPath:
        (nonnull NSString *)documentPath;

    Parameters

    documentPath

    The slash-separated relative path of the document for which to get a FIRDocumentReference.

    Return Value

    The FIRDocumentReference for the specified document path.

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

    Declaration

    Swift

    func addDocument(data: [String : Any]) -> FIRDocumentReference

    Objective-C

    - (nonnull FIRDocumentReference *)addDocumentWithData:
        (nonnull NSDictionary<NSString *, id> *)data;

    Parameters

    data

    An NSDictionary containing the data for the new document.

    Return Value

    A FIRDocumentReference pointing to the newly created document.

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

    Declaration

    Swift

    func addDocument(data: [String : Any], completion: ((Error?) -> Void)? = nil) -> FIRDocumentReference

    Objective-C

    - (nonnull FIRDocumentReference *)
    addDocumentWithData:(nonnull NSDictionary<NSString *, id> *)data
             completion:(nullable void (^)(NSError *_Nullable))completion;

    Parameters

    data

    An NSDictionary containing the data for the new document.

    completion

    A block to execute once the document has been successfully written.

    Return Value

    A FIRDocumentReference pointing to the newly created document.