FIRDocumentReference


@interface FIRDocumentReference : NSObject

A FIRDocumentReference 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. A FIRDocumentReference can also be used to create a FIRCollectionReference to a subcollection.

  • Declaration

    Objective-C

    - (nonnull instancetype)init;
  • The ID of the document referred to.

    Declaration

    Swift

    var documentID: String { get }

    Objective-C

    @property (readonly, strong, nonatomic) NSString *_Nonnull documentID;
  • A reference to the collection to which this DocumentReference belongs.

    Declaration

    Swift

    var parent: FIRCollectionReference { get }

    Objective-C

    @property (readonly, strong, nonatomic) FIRCollectionReference *_Nonnull parent;
  • The FIRFirestore for the Firestore database (useful for performing transactions, etc.).

    Declaration

    Swift

    var firestore: FIRFirestore { get }

    Objective-C

    @property (readonly, strong, nonatomic) FIRFirestore *_Nonnull firestore;
  • A string representing the path of the referenced document (relative to the root of the database).

    Declaration

    Swift

    var path: String { get }

    Objective-C

    @property (readonly, strong, nonatomic) NSString *_Nonnull path;
  • Gets a FIRCollectionReference referring to the collection at the specified path, relative to this document.

    Declaration

    Swift

    func collection(_ collectionPath: String) -> FIRCollectionReference

    Objective-C

    - (nonnull FIRCollectionReference *)collectionWithPath:
        (nonnull NSString *)collectionPath;

    Parameters

    collectionPath

    The slash-separated relative path of the collection for which to get a FIRCollectionReference.

    Return Value

    The FIRCollectionReference at the specified collectionPath.

  • Writes to the document referred to by FIRDocumentReference. If the document doesn’t yet exist, this method creates it and then sets the data. If the document exists, this method overwrites the document data with the new values.

    Declaration

    Swift

    func setData(_ documentData: [String : Any])

    Objective-C

    - (void)setData:(nonnull NSDictionary<NSString *, id> *)documentData;

    Parameters

    documentData

    An NSDictionary that contains the fields and data to write to the document.

  • Writes to the document referred to by this DocumentReference. If the document does not yet exist, it will be created. If you pass FIRSetOptions, the provided data will be merged into an existing document.

    Declaration

    Swift

    func setData(_ documentData: [String : Any], options: FIRSetOptions)

    Objective-C

    - (void)setData:(nonnull NSDictionary<NSString *, id> *)documentData
            options:(nonnull FIRSetOptions *)options;

    Parameters

    documentData

    An NSDictionary that contains the fields and data to write to the document.

    options

    A FIRSetOptions used to configure the set behavior.

  • Overwrites the document referred to by this FIRDocumentReference. If no document exists, it is created. If a document already exists, it is overwritten.

    Declaration

    Swift

    func setData(_ documentData: [String : Any], completion: ((Error?) -> Void)? = nil)

    Objective-C

    - (void)setData:(nonnull NSDictionary<NSString *, id> *)documentData
         completion:(nullable void (^)(NSError *_Nullable))completion;

    Parameters

    documentData

    An NSDictionary containing the fields that make up the document to be written.

    completion

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

  • Writes to the document referred to by this DocumentReference. If the document does not yet exist, it will be created. If you pass FIRSetOptions, the provided data will be merged into an existing document.

    Declaration

    Swift

    func setData(_ documentData: [String : Any], options: FIRSetOptions, completion: ((Error?) -> Void)? = nil)

    Objective-C

    - (void)setData:(nonnull NSDictionary<NSString *, id> *)documentData
            options:(nonnull FIRSetOptions *)options
         completion:(nullable void (^)(NSError *_Nullable))completion;

    Parameters

    documentData

    An NSDictionary containing the fields that make up the document to be written.

    options

    A FIRSetOptions used to configure the set behavior.

    completion

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

  • Updates fields in the document referred to by this FIRDocumentReference. If the document does not exist, the update fails (specify a completion block to be notified).

    Declaration

    Swift

    func updateData(_ fields: [AnyHashable : Any])

    Objective-C

    - (void)updateData:(nonnull NSDictionary<id, id> *)fields;

    Parameters

    fields

    An NSDictionary containing the fields (expressed as an NSString or FIRFieldPath) and values with which to update the document.

  • Updates fields in the document referred to by this FIRDocumentReference. If the document does not exist, the update fails and the specified completion block receives an error.

    Declaration

    Swift

    func updateData(_ fields: [AnyHashable : Any], completion: ((Error?) -> Void)? = nil)

    Objective-C

    - (void)updateData:(nonnull NSDictionary<id, id> *)fields
            completion:(nullable void (^)(NSError *_Nullable))completion;

    Parameters

    fields

    An NSDictionary containing the fields (expressed as an NSString or FIRFieldPath) and values with which to update the document.

    completion

    A block to execute when the update is complete. If the update is successful the error parameter will be nil, otherwise it will give an indication of how the update failed.

  • Deletes the document referred to by this FIRDocumentReference.

    Declaration

    Swift

    func delete()

    Objective-C

    - (void)deleteDocument;
  • Deletes the document referred to by this FIRDocumentReference.

    Declaration

    Swift

    func delete(completion: ((Error?) -> Void)? = nil)

    Objective-C

    - (void)deleteDocumentWithCompletion:
        (nullable void (^)(NSError *_Nullable))completion;

    Parameters

    completion

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