【问题标题】:Create Firestore database documents from Postman从 Postman 创建 Firestore 数据库文档
【发布时间】:2020-02-07 01:00:27
【问题描述】:

我正在尝试在 Firestore 集合中一次创建多个文档以进行配置。我可以从 Postman 发送一份一份地创建文档:

{
    "fields": {
        "category":{"stringValue": "Configs"},
        "order":{"integerValue":"3"}
    }
} 

我想知道是否有某种方法可以创建多个发送这样的文件:

{
    "batch": [
        {
            "fields": {
                "categoria": {
                    "stringValue": "Configurações"
                },
                "ordem": {
                    "integerValue": "3"
                }
            }
        },
        {
            "fields": {
                "categoria": {
                    "stringValue": "Configurações"
                },
                "ordem": {
                    "integerValue": "3"
                }
            }
        }
    ]
}

谁能说这可能吗?如果是这样,我该怎么做?

【问题讨论】:

  • 你做对了吗?

标签: json rest api google-cloud-firestore postman


【解决方案1】:

类似下面的东西应该可以工作。

虽然这是一个“更新”操作,但如果它们不存在,也会创建新文档。必须提供文档 ID,不能使用提交端点自动生成。

查看response 详细说明commit 的使用后,我能够让我的用例工作。

API 端点:https://firestore.googleapis.com/v1/projects/projectID/databases/(default)/documents:commit

{
    "writes": [
        {
            "update": {
                "name": "projects/projectID/databases/(default)/documents/test/ExistingDocumentID1",
                "fields": {
                    "comment": {
                        "stringValue": "Hello World!"
                    }
                }
            }
        },
        {
            "update": {
                "name": "projects/projectID/databases/(default)/documents/test/NewManualDocumentID2",
                "fields": {
                    "comment": {
                        "stringValue": "Happy Birthday!"
                    }
                }
            }
        }
    ]
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-10-01
    • 1970-01-01
    • 1970-01-01
    • 2018-09-03
    • 2019-01-03
    • 2021-01-21
    • 1970-01-01
    • 2017-05-25
    相关资源
    最近更新 更多