php - 在 firestore (php) 中增加一个字段

标签 php firebase google-cloud-firestore

我正在寻找一种方法来增加 firestore 中的字段,例如 this documentation .

shard_ref.update("count", firebase.firestore.FieldValue.increment(1));

唯一需要注意的是我正在尝试使用 firestore Client SdkAdmin Sdk用于 PHP。

什么是在 php.ini 中递增字段的干净解决方案?它需要读写操作还是只需要写操作?

最佳答案

Firestore Client Sdk具有增加字段的能力。 (使用负值递减)。 您可以通过以下方式使用它来更新带有 $field_name 的字段:

$data = [
            [
                   'path' => $field_name,
                   'value' => \Google\Cloud\Firestore\FieldValue::increment($increment_value);
            ]
        ];     
$doc_ref->update($data);

如果您正在使用批处理,您可以按如下方式调用它

$data[$field_name] = \Google\Cloud\Firestore\FieldValue::increment($increment_value);
$batch->add_to_batch('update', $doc_ref, $data);

这是额外的reference

关于php - 在 firestore (php) 中增加一个字段,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57120363/

相关文章:

php - 点击 'home' -logo 返回 404 错误页面

performance - 如何清除 Firebase 实时数据库中的旧内容

firebase - List.contains()在Firestore文档列表上不起作用

php - 日语的 sort()

php - CURLOPT_TIMEOUT 不适用于curl_multi

PHP:如何将 3D 数组转换为 mysql 结果对象?

firebase - flutter 包 flutter_stripe 是否需要后端来处理付款?

firebase - 将instagram之类的rdms转换为firebase nosql

google-cloud-firestore - 了解分布式系统中的一致性

firebase - Firestore 规则和使用电子邮件 key 查询文档映射以与用户共享数据