在https://github.com/GoogleCloudPlatform/php-docs-samples/blob/master/firestore/src/get_all_docs.php的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)显示:
[06-May-2018 22:24:26 UTC] PHP Warning: Module 'protobuf' already loaded in Unknown on line 0
[06-May-2018 22:24:26 UTC] PHP Warning: Module 'protobuf' already loaded in Unknown on line 0
[06-May-2018 22:24:27 UTC] PHP Fatal error: Call to undefined method Google\Protobuf\Timestamp::getFields() in /home/user/public_html/my/vendor/google/gax/src/ApiCore/Serializer.php on line 222
[06-May-2018 22:25:02 UTC] PHP Warning: Module 'protobuf' already loaded in Unknown on line 0
[06-May-2018 22:25:02 UTC] PHP Warning: Module 'protobuf' already loaded in Unknown on line 0
我知道Firestore仍处于测试阶段。这是已知问题/限制之一吗?
答案 0 :(得分:1)
作为一种解决方法,我能够从嵌套文档中获取数据,如下所示:
comments