CollectionReference
class CollectionReference : Query, @unchecked SendableA CollectionReference object can be used for adding documents, getting document references,
and querying for documents (using the methods inherited from Query).
-
ID of the referenced collection.
Declaration
Swift
var collectionID: String { get } -
For subcollections,
parentreturns the containingDocumentReference. For root collections,nilis returned.Declaration
Swift
var parent: FIRDocumentReference? { get } -
A string containing the slash-separated path to this this
CollectionReference(relative to the root of the database).Declaration
Swift
var path: String { get } -
Returns a
DocumentReferencepointing to a new document with an auto-generated ID.Declaration
Swift
func document() -> FIRDocumentReferenceReturn Value
A
DocumentReferencepointing to a new document with an auto-generated ID. -
Gets a
DocumentReferencereferring to the document at the specified path, relative to this collection’s own path.Declaration
Swift
func document(_ documentPath: String) -> FIRDocumentReferenceParameters
documentPathThe slash-separated relative path of the document for which to get a
DocumentReference.Return Value
The
DocumentReferencefor the specified document path. -
Adds a new document to this collection with the specified data, assigning it a document ID automatically.
Declaration
Swift
func addDocument(data: [String : Any]) -> FIRDocumentReferenceParameters
dataA
Dictionarycontaining the data for the new document.Return Value
A
DocumentReferencepointing to the newly created document. -
Adds a new document to this collection with the specified data, assigning it a document ID automatically.
Declaration
Swift
func addDocument(data: [String : Any], completion: (((any Error)?) -> Void)? = nil) -> FIRDocumentReferenceParameters
dataA
Dictionarycontaining the data for the new document.completionA block to execute once the document has been successfully written to the server. This block will not be called while the client is offline, though local changes will be visible immediately.
Return Value
A
DocumentReferencepointing to the newly created document. -
Adds a new document to this collection with the specified data, assigning it a document ID automatically.
Throws
Errorif the backend rejected the write.Declaration
Swift
@discardableResult func addDocument(data: [String : Any]) async throws -> DocumentReferenceParameters
dataA
Dictionarycontaining the data for the new document.Return Value
A
DocumentReferencepointing to the newly created document. -
Encodes an instance of
Encodableand adds a new document to this collection with the encoded data, assigning it a document ID automatically.See
Firestore.Encoderfor more details about the encoding process.Declaration
Swift
@discardableResult func addDocument<T: Encodable>(from value: T, encoder: Firestore.Encoder = Firestore.Encoder(), completion: ((Error?) -> Void)? = nil) throws -> DocumentReferenceParameters
valueAn instance of
Encodableto be encoded to a document.encoderAn encoder instance to use to run the encoding.
completionA block to execute once the document has been successfully written to the server. This block will not be called while the client is offline, though local changes will be visible immediately.
Return Value
A
DocumentReferencepointing to the newly created document.