Class: Google::Cloud::Firestore::CollectionReference
- Defined in:
- lib/google/cloud/firestore/collection_reference.rb
Overview
CollectionReference
A collection reference object is used for adding documents, getting document references, and querying for documents (See Query).
Access collapse
-
#doc(document_path = nil) ⇒ DocumentReference
(also: #document)
Retrieves a document reference.
-
#list_documents(token: nil, max: nil) ⇒ Array<DocumentReference>
Retrieves a list of document references for the documents in this collection.
-
#parent ⇒ Client, DocumentReference
The document reference or database the collection reference belongs to.
Modifications collapse
-
#add(data = nil) ⇒ DocumentReference
Create a document with random document identifier.
Instance Method Summary collapse
-
#collection_id ⇒ String
The collection identifier for the collection resource.
-
#collection_path ⇒ String
A string representing the path of the collection, relative to the document root of the database.
Methods inherited from Query
#end_at, #end_before, #get, #limit, #limit_to_last, #listen, #offset, #order, #select, #start_after, #start_at, #where
Instance Method Details
#add(data = nil) ⇒ DocumentReference
Create a document with random document identifier.
The operation will fail if the document already exists.
241 242 243 244 |
# File 'lib/google/cloud/firestore/collection_reference.rb', line 241 def add data = nil data ||= {} doc.tap { |d| d.create data } end |
#collection_id ⇒ String
The collection identifier for the collection resource.
54 55 56 |
# File 'lib/google/cloud/firestore/collection_reference.rb', line 54 def collection_id path.split("/").last end |
#collection_path ⇒ String
A string representing the path of the collection, relative to the document root of the database.
63 64 65 |
# File 'lib/google/cloud/firestore/collection_reference.rb', line 63 def collection_path path.split("/", 6).last end |
#doc(document_path = nil) ⇒ DocumentReference Also known as: document
Retrieves a document reference.
122 123 124 125 126 127 |
# File 'lib/google/cloud/firestore/collection_reference.rb', line 122 def doc document_path = nil document_path ||= random_document_id ensure_client! client.doc "#{collection_path}/#{document_path}" end |
#list_documents(token: nil, max: nil) ⇒ Array<DocumentReference>
Retrieves a list of document references for the documents in this collection.
The document references returned may include references to "missing
documents", i.e. document locations that have no document present but
which contain subcollections with documents. Attempting to read such a
document reference (e.g. via DocumentReference#get) will return
a DocumentSnapshot whose exists?
method returns false.
157 158 159 160 161 |
# File 'lib/google/cloud/firestore/collection_reference.rb', line 157 def list_documents token: nil, max: nil ensure_client! client.list_documents \ parent_path, collection_id, token: token, max: max end |
#parent ⇒ Client, DocumentReference
The document reference or database the collection reference belongs to. If the collection is a root collection, it will return the client object. If the collection is nested under a document, it will return the document reference object.
193 194 195 196 197 198 |
# File 'lib/google/cloud/firestore/collection_reference.rb', line 193 def parent if collection_path.include? "/" return DocumentReference.from_path parent_path, client end client end |