如何在PHP中添加Firestore引用类型字段?

时间:2019-08-27 18:02:18

标签: php google-cloud-firestore

我想将具有引用字段类型的数据添加到我的集合中。如何在PHP中编写代码?

我添加了:

$db = new FirestoreClient([
    'projectId' => $projectId,
]);

$addedDocRef = $db->collection('locations')->newDocument();
$addedDocRef->set([
    'decisionRef' => $db->document('decisions/' . $ID),
    'formattedAddress' => $formattedAddress,
    'point' => [
        'geohash' => $geohash,
        'geopoint' => new GeoPoint($lat,$lng)
    ]
]);

我希望在文档中看到一个引用类型字段,但出现此错误:

  

未捕获的Google \ ApiCore \ ValidationException:呈现'projects / {project = } / databases / {database = }'时出错:预期的绑定...

1 个答案:

答案 0 :(得分:0)

解决方案是在set([...])数组外设置$ decisionRef

var area = d3 .area() .x(function(d) { return xScale(d.startTime); }) .y0(function(d) { return yScale(d.magnitude); }) .y1(yScale(0));