CollectionReference
public extension CollectionReference-
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
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
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.