duanbi8529 2017-02-09 04:36
浏览 102
已采纳

Firebase更新多个项目

How can I update multiple items on firebase with just one request?

I can not let my system wait to complete multiple requests, so I need to update them with just one.


Current Firebase Data:

enter image description here


PHP Code:

$data = [
    'mydata-1' => [
        'position' => 1,
    ],
    'mydata-2' => [
        'position' => 2,
    ],
];

$client = new \GuzzleHttp\Client();
$response = $client->put(FIREBASE_ENDPOINT . '/data', [
    'json' => $data,
]);

Expected Firebase Data:

enter image description here


Problem:

The request subscribe all my data and I lose the title field. I also tried PATCH request, but I got the same response.

enter image description here

  • 写回答

1条回答 默认 最新

  • dongpu5874 2017-02-09 19:52
    关注

    Based on Frank van Puffelen comment:

    $data = [
        'mydata-1/position' => 1,
        'mydata-2/position' => 2,
    ];
    
    $client = new \GuzzleHttp\Client();
    $response = $client->patch(FIREBASE_ENDPOINT . '/data', [
        'json' => $data,
    ]);
    

    Documentation: https://firebase.googleblog.com/2015/09/introducing-multi-location-updates-and_86.html

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

报告相同问题?