简体   繁体   English

使用 REST API 创建新的 firestore 文档

[英]Create new firestore document with REST API

I'm trying to create a new document id and store my collection inside it.我正在尝试创建一个新的文档 ID 并将我的收藏存储在其中。 My post looks like this:我的帖子看起来像这样:

{     
 "name": "projects/<project-id>/databases/(default)/documents/users/cena123",

  "fields": {
    "name": {
      "stringValue": "tom"
    },
    "lname": {
      "stringValue": "cruise"
    }

ERROR i get:错误我得到:

error": { "code": 400, "message": "Invalid JSON payload received. Unknown name \" {\r\n \"name\": \"projects/mountain-bear-****/databases/(default)/documents/users/cena123\",\r\n

What T'm trying to achieve: T 想要达到的目标:

  1. Create a document called: "cena123"创建一个名为:“cena123”的文档
  2. Add name and lname fields under the document在文档下添加name和lname字段

The reason you are receiving "code": 400, "message": "Invalid JSON payload received. Unknown name error, is because name should not be passed in the request body, unless it's inside the fields object. Use the below json in your request body.您收到"code": 400, "message": "Invalid JSON payload received. Unknown name错误,是因为name不应在请求正文中传递,除非它在字段 object 内。在您的字段中使用以下 json请求正文。

 {
      "fields": {
        "name": {
          "stringValue": "tom"
        },
        "lname": {
          "stringValue": "cruise"
        }
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM