在 Cloud Functions 中,将 JSON 写入 Cloud Firestore 中的 Map 数据类型的语法是什么?

In Cloud Functions, what is the syntax for writing a JSON to the Map data type in Cloud Firestore?

我正在编写一个 Google Cloud Function,它接收 Webhook JSON 负载,解析 JSON 并将数据写入 Cloud Firestore。

我在 Cloud Firestore 中收集了一个字符串映射。(“订单”).doc():

customerNote (map)
     customerNote1 (string)
     customerNote2 (string)
     customerNote3 (string)

对于一个简单的字符串,在 Cloud Functions 中写入 Cloud Firestore 的语法如下:

await admin.firestore().collection("orders").doc().set({
orderNameInFirestore: data.orderNamefromJSON
})

字符串映射的云函数是什么样的?

Firestore 可以接受和存储任意 JavaScript 对象(有一些限制)。例如:

const myMap = {"key-one": "abc", "key-two": 123};

await admin.firestore().collection("orders").add({
  mappedData: myMap
});

只要地图大小合理,上述方法就可以正常工作。