gpt4 book ai didi

php - Firestore : Key writes does not exist in the provided array

转载 作者:塔克拉玛干 更新时间:2023-11-03 05:43:19 26 4
gpt4 key购买 nike

谁能告诉我,以下错误消息试图告诉我什么?

Fatal error: Uncaught exception 'InvalidArgumentException' with message 'Key writes does not exist in the provided array.' in /vendor/google/cloud/Core/src/ArrayTrait.php:38

Stack trace: 
#0 /vendor/google/cloud/Firestore/src/Connection/Grpc.php(127): Google\Cloud\Firestore\Connection\Grpc->pluck('writes', Array)
#1 /vendor/google/cloud/Firestore/src/WriteBatch.php(381): Google\Cloud\Firestore\Connection\Grpc->commit(Array)
#2 import.php(45): Google\Cloud\Firestore\WriteBatch->commit()
#3 {main} thrown in /vendor/google/cloud/Core/src/ArrayTrait.php on line 38

我的代码如下:

$batch = $project->db->batch();
foreach($memberList as $member){
$addedDocRef = $collection->newDocument();
$data["id"] = $addedDocRef->id();
$data["creation"] = $this->generateCreation();
$data["publication"] = $this->generatePublication();
$batch->create($addedDocRef, $data);
}
$batch->commit();

最佳答案

它告诉您您正在运行提交,但批处理不包含任何操作。可能当您的 $memberList 为空时会出现此错误。防止错误的一种简单方法是:

if (! empty($memberList)) {
$batch->commit();
}

此外,您确定 $batch->create() 存在吗?你应该使用 set() 方法。这是最新的 firestore 文档:

$batch = $db->batch();

# Set the data for NYC
$nycRef = $db->collection('cities')->document('NYC');
$batch->set($nycRef, [
'name' => 'New York City'
]);

# Update the population for SF
$sfRef = $db->collection('cities')->document('SF');
$batch->update($sfRef, [
['path' => 'population', 'value' => 1000000]
]);

# Delete LA
$laRef = $db->collection('cities')->document('LA');
$batch->delete($laRef);

# Commit the batch
$batch->commit();

关于php - Firestore : Key writes does not exist in the provided array,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51569285/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com