Skip to content

Conversation

@vishwarajanand
Copy link
Contributor

Per googleapis/google-cloud-php#2542, user claimed that they cannot get the collectionGroup query return successfully. Upon investigation, it seems we disable indexes on collection group by default: source link to docs.

Changes summary

  1. Adding a comment in the sample to ensure users have more clarity for querying collection groups.
  2. Linked the source docs page about automatic indexing

Tests

  1. Created a document structure within a subcollection

Screenshot 2022-05-11 at 11 32 52

  1. Created a single field index within a field of subcollection so that it can be queried

Screenshot 2022-05-11 at 11 33 35

  1. Renamed the subcollection, field and value identifiers in this PHP sample and I get the following output.
function query_collection_group_filter_eq(string $projectId): void
{
    // Create the Cloud Firestore client
    $db = new FirestoreClient([
        'projectId' => $projectId,
    ]);

    $results = $db->collectionGroup('subcollection')->where('f1', '==', 'v1');
    foreach ($results->documents() as $document) {
        printf('%s => %s' . PHP_EOL, $document->id(), $document->data()['name']);
    }
}

// Produces the following output:
➜  firestore git:(master) ✗ php src/query_collection_group_filter_eq.php $GOOGLE_PROJECT_ID
subcollection_doc1 => subcollection_doc1
➜  firestore git:(master) ✗

Screenshot 2022-05-11 at 11 37 24

@vishwarajanand vishwarajanand self-assigned this May 11, 2022
@vishwarajanand vishwarajanand requested a review from a team as a code owner May 11, 2022 06:37
@product-auto-label product-auto-label bot added the samples Issues that are directly related to samples. label May 11, 2022
Copy link
Collaborator

@saranshdhingra saranshdhingra left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@saranshdhingra saranshdhingra merged commit 096b285 into GoogleCloudPlatform:master May 11, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

samples Issues that are directly related to samples.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants