CollectionReference
class CollectionReference : Query
A 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,
parent
returns the containingDocumentReference
. For root collections,nil
is 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
DocumentReference
pointing to a new document with an auto-generated ID.Declaration
Swift
func document() -> FIRDocumentReference
Return Value
A
DocumentReference
pointing to a new document with an auto-generated ID. -
Gets a
DocumentReference
referring to the document at the specified path, relative to this collection’s own path.Declaration
Swift
func document(_ documentPath: String) -> FIRDocumentReference
Parameters
documentPath
The slash-separated relative path of the document for which to get a
DocumentReference
.Return Value
The
DocumentReference
for 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]) -> FIRDocumentReference
Parameters
data
A
Dictionary
containing the data for the new document.Return Value
A
DocumentReference
pointing 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: ((Error?) -> Void)? = nil) -> FIRDocumentReference
Parameters
data
A
Dictionary
containing the data for the new document.completion
A 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
DocumentReference
pointing to the newly created document.