FireStoreRESTAPI:如何使用REST命令向文档添加子集合?
使用FireStore的REST API记录在: 我正在尝试在“users”中创建一个新文档,该文档的子集合名为“subcol1”,其中有一个名为“subdoc1”的空文档 但是,以下用于创建新文档的REST命令无效:FireStoreRESTAPI:如何使用REST命令向文档添加子集合?,rest,collections,google-cloud-firestore,Rest,Collections,Google Cloud Firestore,使用FireStore的REST API记录在: 我正在尝试在“users”中创建一个新文档,该文档的子集合名为“subcol1”,其中有一个名为“subdoc1”的空文档 但是,以下用于创建新文档的REST命令无效: curl -X POST -H "Content-Type: application/json" -d "{ 'fields': { 'subcol1': [{'subdoc1': { 'fields': {} } }] } }" "https://firestore.goo
curl -X POST
-H "Content-Type: application/json"
-d "{ 'fields': { 'subcol1': [{'subdoc1': { 'fields': {} } }] } }"
"https://firestore.googleapis.com/v1/projects/XXXX/databases/(default)/documents/users"
如何使用FireStore的RESTAPI将子集合添加到新文档(或现有文档?)中
对于这个实现,我特别需要使用REST
这是我得到的错误响应:
{ "error": {
"code": 400,
"message": "Invalid value at 'document.fields[0].value' (Map), Cannot have repeated items ('subcol1') within a map.\nInvalid JSON payload received. Unknown name \"\" at 'document.fields[0].value': Proto fields must have a name.",
"status": "INVALID_ARGUMENT",
"details": [
{
"@type": "type.googleapis.com/google.rpc.BadRequest",
"fieldViolations": [
{
"field": "document.fields[0].value",
"description": "Invalid value at 'document.fields[0].value' (Map), Cannot have repeated items ('subcol1') within a map."
},
{
"field": "document.fields[0].value",
"description": "Invalid JSON payload received. Unknown name \"\" at 'document.fields[0].value': Proto fields must have a name."
}
]
}
] } }
谢谢 在对此进行了更多的修补之后,我找到了一个解决方案 以下工作:
curl -X POST
-H "Content-Type: application/json"
-d "{ 'fields': { } }"
"https://firestore.googleapis.com/v1/projects/XXXX/databases/(default)/documents/users"
curl -X POST
-H "Content-Type: application/json"
-d "{ 'fields': { } }"
"https://firestore.googleapis.com/v1/projects/XXXX/databases/(default)/documents/
users/<USER-KEY-FROM-PREVIOUS-JSON-RESPONSE>/subcol1"
然后创建子文档(“创建”子集合):
curl -X POST
-H "Content-Type: application/json"
-d "{ 'fields': { } }"
"https://firestore.googleapis.com/v1/projects/XXXX/databases/(default)/documents/users"
curl -X POST
-H "Content-Type: application/json"
-d "{ 'fields': { } }"
"https://firestore.googleapis.com/v1/projects/XXXX/databases/(default)/documents/
users/<USER-KEY-FROM-PREVIOUS-JSON-RESPONSE>/subcol1"
curl-X POST
-H“内容类型:应用程序/json”
-d“{‘字段’:{}”
"https://firestore.googleapis.com/v1/projects/XXXX/databases/(默认)/文件/
用户//subcol1“
如果“顶级”文档不必包含任何数据,我认为您不必创建该文档。SDK不要求您这样做。可以在不存在的文档下组织子集合。它将以斜体显示在控制台中,您可以单击它的子集合。