Http Firebase REST API-Guzzle修补程序请求正在删除数据

Http Firebase REST API-Guzzle修补程序请求正在删除数据,http,rest,firebase,guzzle,Http,Rest,Firebase,Guzzle,根据firebase文档,它指出: PATCH - Updating Data You can update specific children at a location without overwriting existing data with a PATCH request. Named children in the data being written with PATCH will be written, but omitted children will not be del

根据firebase文档,它指出:

PATCH - Updating Data
You can update specific children at a location without overwriting existing data 
with a PATCH request. Named children in the data being written with PATCH will be 
written, but omitted children will not be deleted. This is equivalent to the 
update( ) function.

curl -X PATCH -d '{"last":"Jones"}' \
 https://SampleChat.firebaseIO-demo.com/users/jack/name/.json
A successful request will be indicated by a 200 OK HTTP status code. 
The response will contain the data written:

{"last":"Jones"}
现在我的理解是,如果我只想更新资源的一部分,那么我可以使用补丁请求

我的简化firebase数据库如下所示:

  "exchange-rates" : {
    "eur" : {
      "fx" : 1.2,
      "currency_symbol" : "€",
      "updated_at" : "2014-06-13T22:49:23+0100",
    },
    "usd" : {
      "fx" : 1.6,
      "currency_symbol" : "$",
      "updated_at" : "2014-06-13T22:49:23+0100",
    },
    "gbp" : {
      "fx" : 1,
      "currency_symbol" : "£",
      "updated_at" : "2014-06-16T15:43:15+0100",
    }
  }
但是,如果我在补丁请求中从有效负载中省略了
货币符号
更新的
,那么Firebase将从数据库中删除这些属性

    $auth = 'SUPER_SECRET_CODE';
    $guzzleClient = new GuzzleHttp\Client();
    $url = https://DATABASE.firebaseio.com/.json;


    $data['exchange-rates']['gbp']['fx'] = (float) 1;
    $data['exchange-rates']['usd']['fx'] = (float) 1.66;
    $data['exchange-rates']['eur']['fx'] = (float) 1.22;

    $payload =
        [
            'query' => [ 'auth' => $auth ],
            'json' => $data
        ];

    $response = $guzzleClient->patch($url, $payload);
因此,补丁请求不能正常工作,或者我误解了Firebase应该如何处理这个补丁请求,或者我遗漏了一些东西。有什么想法吗

此外,如果我希望向汇率对象添加对象,我应该能够这样做

$data['exchange-rates']['chf']['fx'] = 2.13;

    $payload =
        [
            'query' => [ 'auth' => $auth ],
            'json' => $data
        ];

    $response = $guzzleClient->patch($url, $payload);

然而,所有这些只是覆盖所有现有的汇率,现在我在数据库中只有一个汇率。

更新/修补操作不是递归的。他们只观察更新的直接子项的键。例如:

// assume data:  { foo: 'bar', baz: {uno: 1, dos: 2}, zeta: {hello: 'world'} };

curl -X PATCH -d  '{"tres": 3}' $URL

// baz is now: {uno: 1, dos: 2, tres: 3}

curl -X PATCH -d '{"foo": "barr", baz: {"tres": 3}}' $URL

// baz is now {tres: 3}
因此,更新只有一个层次的深度。如果您提供的其中一个子记录是对象,它将替换该路径上的子记录,而不是尝试合并这两个记录