Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/postgresql/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
无法使用PHP从具有Cloud Firestore的嵌套集合中获取文档_Php_Google Cloud Firestore - Fatal编程技术网

无法使用PHP从具有Cloud Firestore的嵌套集合中获取文档

无法使用PHP从具有Cloud Firestore的嵌套集合中获取文档,php,google-cloud-firestore,Php,Google Cloud Firestore,根据Google的官方文档,我无法检索嵌套集合中的文档,即: $db = new FirestoreClient([ 'projectId' => $projectId, ]); //$citiesRef = $db->collection('cities'); //working original example $citiesRef = $db->collection('countries')->document('USA')->collection('

根据Google的官方文档,我无法检索嵌套集合中的文档,即:

$db = new FirestoreClient([
    'projectId' => $projectId,
]);
//$citiesRef = $db->collection('cities'); //working original example
$citiesRef = $db->collection('countries')->document('USA')->collection('cities'); //this throws an HTTP Error 500 
$documents = $citiesRef->documents();
foreach ($documents as $document) {
    if ($document->exists()) {
        printf('Document data for document %s:' . PHP_EOL, $document->id());
        print_r($document->fields());
        printf(PHP_EOL);
    } else {
        printf('Document %s does not exist!' . PHP_EOL, $snapshot->id());
    }
}
上面的代码抛出HTTP错误500。以下是我的示例数据库:

错误日志(CentOS 6)显示:


我知道Firestore仍处于测试阶段。这是已知的问题/限制之一吗?

作为一种解决方法,我可以从嵌套文档中获取数据,如下所示:

$db = new FirestoreClient([
    'projectId' => $projectId,
]);
//$citiesRef = $db->collection('cities'); //working original example
$citiesRef = $db->collection('countries')->document('USA')->collection('cities');
$documents = $citiesRef->select(['capital','country','name','population','state'])->documents();
foreach ($documents as $document) {
    if ($document->exists()) {
        printf('Document data for document %s:' . PHP_EOL, $document->id());
        //print_r($document->fields()); //this no longer works
        print_r($document->data());
        printf(PHP_EOL);
    } else {
        printf('Document %s does not exist!' . PHP_EOL, $snapshot->id());
    }
}

我从Google的示例中逐字复制了这段代码。请注意,行
printf('文档%s不存在!'.PHP_EOL,$snapshot->id())else
闭包中的code>引用未定义的变量
$snapshot
$db = new FirestoreClient([
    'projectId' => $projectId,
]);
//$citiesRef = $db->collection('cities'); //working original example
$citiesRef = $db->collection('countries')->document('USA')->collection('cities');
$documents = $citiesRef->select(['capital','country','name','population','state'])->documents();
foreach ($documents as $document) {
    if ($document->exists()) {
        printf('Document data for document %s:' . PHP_EOL, $document->id());
        //print_r($document->fields()); //this no longer works
        print_r($document->data());
        printf(PHP_EOL);
    } else {
        printf('Document %s does not exist!' . PHP_EOL, $snapshot->id());
    }
}