无法通过Firestore API添加文档.错误400资源名称...缺少\"projects \"在索引0 [英] Can't add document from Firestore API. Error 400 Resource name ... lacks \"projects\" at index 0

查看:53
本文介绍了无法通过Firestore API添加文档.错误400资源名称...缺少\"projects \"在索引0的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试从Firestore API Explorer添加一个文档.

I try to add one document from Firestore API Explorer.

这是我尝试插入的数据:

This is the data i try to insert:

POST https://firestore.googleapis.com/v1/projects/myProjetID/databases/(default)/documents/myCollection/2019/04?documentId=10&key={YOUR_API_KEY}

{
 "fields": {
  "field0": {
   "referenceValue": "ref0"
  }
 }
}

我遇到此错误:

cache-control:  private
content-encoding:  gzip
content-length:  143
content-type:  application/json; charset=UTF-8
date:  Mon, 08 Apr 2019 09:24:09 GMT
server:  ESF
vary:  Origin, X-Origin, Referer

{
 "error": {
  "code": 400,
  "message": "Resource name \"ref0\" lacks \"projects\" at index 0.",
  "status": "INVALID_ARGUMENT"
 }
}

我不知道怎么了.

推荐答案

这是因为您尝试使用"referenceValue" 写入 Reference 类型的字段的值strong>,请参见 https://firebase.google.com/docs/firestore/manage-data/data-types

This is because, with "referenceValue", you try to write the value of a field of type Reference, see https://firebase.google.com/docs/firestore/manage-data/data-types

您需要指定参考的完整路径(即完整的文档路径),如下所示:

You need to specify the full path of the reference (i.e. the full Document path), as follows:

{
 "fields": {
  "name": {
   "referenceValue": "projects/{myProjetID}/databases/(default)/documents/{collectionName}/{documentId}"
  }
 }
}

它将以/{collectionName}/{documentId}

这篇关于无法通过Firestore API添加文档.错误400资源名称...缺少\"projects \"在索引0的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆