duande9301 2019-07-19 22:49
浏览 108
已采纳

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

I am looking for a way to increment a field in firestore like in this documentation.

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

The only caveat is that I am trying to use firestore Client Sdk or the Admin Sdk for php.

What is a clean solution for incrementing a field in php. Does it require both read and write operations or is it possible with only write operation?

  • 写回答

1条回答 默认 最新

  • dongzhiqi0332 2019-07-20 00:29
    关注

    Firestore Client Sdk has the ability to increment a field. (use negative values to decrement). You can use it in the following way to update the field with $field_name:

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

    If you are using a batching you call it as follows

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

    Here is additional reference

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器