Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting An Error when trying to create a subcollection in Firestore

I am trying to create a node in Google Firebase, and use its unique id to create a Document in Google Firestore of the same name.

I'm using Google's PHP Firestore Client: https://github.com/GoogleCloudPlatform/google-cloud-php-firestore

And I've read through their documentation: http://googlecloudplatform.github.io/google-cloud-php/#/docs/cloud-firestore/v0.5.1/firestore/writebatch

Here is my code:

<?php

use \Google\Cloud\Firestore\FirestoreClient;
use \Google\Cloud\Core\Timestamp;
use \Google\Cloud\Firestore\Transaction as FirestoreTransaction;
use \grptx\Firebase as FirebaseClient;

class FirestoreTest
{
    public function create()
    {
        $client = new FirebaseClient();
        $database = $client->getDatabase();

        $org = array(
            "acl" => array(),
            "people" => array()
        );

        $ref = $database->getReference("/clients/")->push($org);
        $key = $ref->getKey();

        $config = array(
            "projectId" => "xxx",
            "keyFile" => json_decode(file_get_contents("/xxx/firebase_auth.json"), true)
        );

        $firestore = new FirestoreClient($config);
        $batch = $firestore->batch();
        $collection = $firestore->collection("clients")->document("-LXXXXXX")->collection("trips");
    }
}

And I get this error:

Exception 'Google\Cloud\Core\Exception\BadRequestException' with message '{
"message": "Document name \"projects\/xxx-test\/databases\/(default)\/documents\/clients\/\" has invalid trailing \"\/\".",
"code": 3,
"status": "INVALID_ARGUMENT",
"details": []
}'

Any help is appreciated.

like image 644
gsposato Avatar asked Nov 05 '25 04:11

gsposato


1 Answers

Basically this will happen if you try to put blank as document name.

like image 156
str028 Avatar answered Nov 08 '25 13:11

str028