为什么我尝试PATCH Firestore记录会替换整个文档?

问题描述 投票:0回答:1

我正在使用cURL编写PHP脚本,以通过Firestore REST API更新Firestore文档中的一些字段。我的问题是,当我运行脚本时,它正在用我正在尝试更新的字段替换整个文档,好像它只是做了一个PUT。有人可以帮我解决这个PHP代码片段吗?

curl_setopt_array($curl, array(
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_CUSTOMREQUEST => 'PATCH',
    CURLOPT_HTTPHEADER => array('Content-Type: application/json',
        'Content-Length: ' . strlen($json),
        'X-HTTP-Method-Override: PATCH'),
    CURLOPT_URL => $url . '?key=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx',
    CURLOPT_USERAGENT => 'cURL',
    CURLOPT_POSTFIELDS => $json
));
$response = curl_exec( $curl );
curl_close( $curl );

有没有明显的东西让我觉得这是Firestore中的PATCH?有什么好的方法可以找出Firestore从我的脚本中收到的内容吗?

php google-cloud-firestore php-curl
1个回答
0
投票

好吧,这是一个古老的问题但仍想解决这个问题。您需要传递updatedMask参数才能将现有文档合并为引用的here,否则它将使用您发送的有效负载替换整个文档。

© www.soinside.com 2019 - 2024. All rights reserved.