Cloud Function 无法写入 Cloud Firestore 中的 Map 数据类型

Cloud Function is failing to write to the Map data type in Cloud Firestore

我有一个 Webhook POSTJSON 我的 Cloud Function Trigger URL。

我希望 Cloud Function 解析 JSON 并将其写入我的 Cloud Firestore。

我已经在 webhook.site 和 requestbin.com 上测试了 Webhook:它们都完美地接收了 POST 请求。

此外,这不是经过身份验证的请求,我通过 Google 云平台 - 云功能控制台部署了该功能。我没有通过 CLI 或通过使用 firebase 的应用程序设置来部署它。

此功能需要 HTTPS。

我能够让我的函数写入 Firestore,但它没有写入 Map 中的字段 - 我在底部包含了屏幕截图以显示我的 Firestore 在 Firebase 中的样子 / Google云平台控制台。

我需要提供什么语法来确保我的 Cloud Function 使用 JSON 并在尊重 Map 数据类型的同时写入 Firestore?

我需要声明 people_Email = 地图吗?如果我这样做,那将如何实现?

index.js

const admin = require('firebase-admin')
admin.initializeApp();

exports.wooCommerceWebhook = async (req, res) => {
    const payload = req.body;

    var billing = ""; // Do I even need to declare every nest of the complex JSON?
        var people_EmailHome = "";
        var people_FirstName = "";
        var people_LastName = "";

    // Write to Firestore - People Collection
    await admin.firestore().collection("people").doc().set({
        people_EmailHome: payload.billing.email,
        people_FirstName: payload.billing.first_name,
        people_LastName: payload.billing.last_name,
    });

    return res.status(200).end();

};

package.json

{
  "name": "sample-http",
  "version": "0.0.1",
  "dependencies": {
      "firebase-admin": "^9.4.2"
  }
}

我的 Webhook 向我的 Cloud Function POST JSON URL:

{
     "billing": {
          "email": "test@test.com",
          "first_name": "First",
          "last_name": "Last"
     }
}

我的 Cloud Firestore 的屏幕截图

What syntax do I need to provide to make sure my Cloud Function takes the JSON and writes to the Firestore while respecting the Map data type?

以下方法可以解决问题:

const admin = require('firebase-admin')
admin.initializeApp();

exports.wooCommerceWebhook = async (req, res) => {
    const payload = req.body;

    await admin.firestore().collection("people").doc().set({
       people_Email: { people_EmailHome: payload.billing.email },
       people_Names: { people_FirstName: payload.billing.first_name, people_LastName: payload.billing.last_name }
    });

    return res.status(200).end();

};