You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When all_descendants is false, selects only collections that are immediate children of the parent specified in the containing RunQueryRequest.
When all_descendants is true, selects all descendant collections.
— CollectionSelector
If the collectionId is from all descendants, so descendent of what? Descente of parent path name.
Currently when use collectionGroup by default parent path name is the root (projects/{projectId}/databases/(default)/documents).
Why the parent path name can't be a document reference path and the query works only inside that path?
Environment details
OS: Ubuntu server
PHP version: 7.3
Package name and version: "google/cloud-firestore": "^1.14.1",
Steps to reproduce
I have 3 collections named people one for organizations, another for schools inside which is inside organizations, and the last inside classroom collection.
Following there is a dump of the query from example code below which we can see that the parentName property has the value projects/gcp-project/databases/(default)/documents .
At this point the query will work to all people collections for the entire project, but I want that query to work only for people collections inside specifique organization.
I have modified the method collectionGroup in Google\Cloud\Firestore\FirestoreClient to test and it works. (I've modified it to tests only, not to production).
Original method code:
publicfunctioncollectionGroup($id)
{
if (strpos($id, '/') !== false) {
thrownew \InvalidArgumentException(
'Collection ID may not contain a slash.'
);
}
returnnewQuery(
$this->connection,
$this->valueMapper,
$this->fullName($this->projectId, $this->database),
[
'from' => [
[
'collectionId' => $id,
'allDescendants' => true
]
]
]
);
}
Modified method code:
publicfunctioncollectionGroup($id, $relativeName = null) // added $relativeName by default null
{
if (strpos($id, '/') !== false) {
thrownew \InvalidArgumentException(
'Collection ID may not contain a slash.'
);
}
returnnewQuery(
$this->connection,
$this->valueMapper,
$this->fullName($this->projectId, $this->database, $relativeName), // added a third parameter
[
'from' => [
[
'collectionId' => $id,
'allDescendants' => true
]
]
]
);
}
@enniopruvo thanks for posting this issue.
It seems you want to scope down your search to ONLY a particular path. I reckon that's not doable so easily. If you have path as one of the key-value pairs in the document, you could achieve this! Also note there's no string contains method, so the path needs to match exactly unless you store path value in the form of an array. Does this help unblock you?
The way you suggested doesn't seem to be a path that other google client libraries such as dotnet, others follow. I am a bit reluctant to make that code change as yet but I will surely raise that up internally. Will update the thread in either case.
In case you are looking to search people documents across subcollection, feel free to refer #2542 (comment) where I explained how having a single field index could help you achieve the same.
If the
collectionId
is from all descendants, so descendent of what? Descente of parent path name.Currently when use
collectionGroup
by default parent path name is the root (projects/{projectId}/databases/(default)/documents
).Why the parent path name can't be a document reference path and the query works only inside that path?
Environment details
Steps to reproduce
I have 3 collections named
people
one fororganizations
, another forschools
inside which is insideorganizations
, and the last insideclassroom
collection.Collection people path examples:
Code example
Following there is a dump of the query from example code below which we can see that the
parentName
property has the valueprojects/gcp-project/databases/(default)/documents
.At this point the query will work to all people collections for the entire project, but I want that query to work only for people collections inside specifique organization.
I have modified the method
collectionGroup
inGoogle\Cloud\Firestore\FirestoreClient
to test and it works. (I've modified it to tests only, not to production).Original method code:
Modified method code:
Dump of query with modified
collectionGroup
This query works perfectly.
My conclusition is that feature is not implemented yet.
The text was updated successfully, but these errors were encountered: