Curtis V. Schleich
Curtis V. Schleich

Reputation: 3

Why does my attempt to PATCH a Firestore record replace the entire document?

I'm writing a PHP script using cURL to update a few fields in a Firestore document via the Firestore REST API. My problem is that when I run the script, it's replacing the entire document with the fields I'm trying to update as if it's simply doing a PUT. Can someone help me out with this PHP snippet?

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 );

Is there something obvious I'm missing here to make this be perceived as a PATCH from Firestore? Is there any decent way to find out what Firestore is receiving from my script?

Upvotes: 0

Views: 381

Answers (1)

Ahsaan Yousuf
Ahsaan Yousuf

Reputation: 715

Well, its an old question but still want to address this issue. You need to pass updatedMask parameter in order to merge with existing document as referenced here, else its going to replace the entire document with the payload you send.

Upvotes: 1

Related Questions