Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Retrieve document and all nested documents in Cloud Firestore #761

Closed
lazharichir opened this issue Nov 27, 2017 · 4 comments
Closed

Retrieve document and all nested documents in Cloud Firestore #761

lazharichir opened this issue Nov 27, 2017 · 4 comments
Assignees
Labels
api: firestore Issues related to the Firestore API. priority: p2 Moderately-important priority. Fix may not be included in next release. type: feature request ‘Nice-to-have’ improvement, new feature or different behavior or design.

Comments

@lazharichir
Copy link

Hello,

I have a collection called Articles containing article documents. Each article document has some fields (title, author, you get the gist) and a sub-collection Blocks which represent paragraphs, sub-titles, images, etc.

I am easily getting the Article object but I have to do another query to receive the Block objects it contains; i.e. two network round-trips, which is not ideal.

Is there are way to query the article in question and retrieve its sub-collections and their documents in full?

/**
 * Populates this object from a database document
 * @param  Google\Cloud\Firestore\DocumentReference &$document Document reference
 * @return object            The populated object
 */
public function populate( &$document ) {

	$snapshot = $document->snapshot();

	$this->setId($snapshot->id() ?? null);

	$this->account 	= $snapshot['account'];
	$this->title 	= $snapshot['title'] ?? 'No title ('.time().')';
	$this->status 	= $snapshot['status'] ?? 'draft';
	$this->seeds 	= [];
	$this->blocks 	= [];

	$blockCollection = $this->firestore()->collection($document->path().'/Blocks');
	# now i have to fetch the documents from this Article's Block subcollection.
}
@dwsupplee dwsupplee added api: firestore Issues related to the Firestore API. type: question Request for information or clarification. Not an issue. labels Nov 28, 2017
@jdpedrie
Copy link
Contributor

Hey @lazharichir, I'm working on getting an answer for this. We'll follow up shortly.

@jdpedrie jdpedrie added priority: p2 Moderately-important priority. Fix may not be included in next release. type: feature request ‘Nice-to-have’ improvement, new feature or different behavior or design. and removed type: question Request for information or clarification. Not an issue. labels Nov 29, 2017
@jdpedrie
Copy link
Contributor

@lazharichir we currently do not have support for this operation. It is planned, but I can't give an estimate at this time.

@lazharichir
Copy link
Author

lazharichir commented Nov 29, 2017 via email

@jdpedrie jdpedrie changed the title How to retrieve a document and its subcollections' documents in php-firestore library? Retrieve document and all nested documents in Cloud Firestore Dec 6, 2017
@jdpedrie
Copy link
Contributor

jdpedrie commented Dec 6, 2017

Moving this to the new Feature Request wiki page.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api: firestore Issues related to the Firestore API. priority: p2 Moderately-important priority. Fix may not be included in next release. type: feature request ‘Nice-to-have’ improvement, new feature or different behavior or design.
Projects
None yet
Development

No branches or pull requests

3 participants