文档父名称缺少Firestore PHP SDK中索引53处的集合ID

时间:2018-05-03 22:05:13

标签: php firebase google-cloud-firestore

我正在尝试查询Google Firestore中的子集合。我的目标是在1970年1月1日之后使用startDate(存储在Google Firestore'时间戳数据类型中)获取所有记录。

我正在使用GoogleCloud Firestore PHP SDK来执行此操作: http://googlecloudplatform.github.io/google-cloud-php/#/docs/cloud-firestore/v0.9.0/firestore/querysnapshot

这是我的代码:

    $config = array(
        "projectId" => "xxx-test",
        "keyFile" => json_decode(file_get_contents("/xxx/firebase_auth.json"), true)
    );
    $firestore = new FirestoreClient($config);
    $collection = $firestore->collection("/clients/-LXXXXXX/trips");
    $query = $collection->where("startDate", ">=", new Timestamp(new \DateTime("Thu Jan 1st 1970")));
    var_dump($query->documents());

我收到了这个错误:

    Exception 'Google\Cloud\Core\Exception\BadRequestException' with message 
    '{
        "message": "Document parent name \"projects\/xxx-test\/databases\/(default)\/documents\/\/clients\/-LXXXXXX\" lacks a collection id at index 53.",
        "code": 3,
        "status": "INVALID_ARGUMENT",
        "details": []
    }'

非常感谢任何帮助。

1 个答案:

答案 0 :(得分:1)

收集路径不会那样工作:

$collection = $firestore->collection("clients")->document("-LXXXXXX")->collection("trips");