Невозможно получить документы из вложенной коллекции с облачным хранилищем пожаров, используя переполнение стека

Следуя официальной документации Google на https://github.com/GoogleCloudPlatform/php-docs-samples/blob/master/firestore/src/get_all_docs.php, Я не могу получить документы, которые являются частью вложенной коллекции, т.е.

$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. Вот мой пример базы данных:

База данных Cloud Firestore, использованная в примере

Журнал ошибок (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

Решение

В качестве обходного пути я могу получить данные из вложенного документа следующим образом:

$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());
}
}
1

Другие решения

Других решений пока нет …

По вопросам рекламы [email protected]