我正在编写一个Google Cloud Function,它接收Webhook JSON有效载荷,解析JSON并将数据写入Cloud Firestore。
我有一个映射的字符串在Cloud Firestore在集合。("orders").doc():
customerNote (map)
customerNote1 (string)
customerNote2 (string)
customerNote3 (string)
对于一个简单的字符串,在Cloud Functions中写入Cloud Firestore的语法可能像这样:
await admin.firestore().collection("orders").doc().set({
orderNameInFirestore: data.orderNamefromJSON
})
对于Map of Strings,这个云函数是什么样子的?
Firestore可以接受和存储任意JavaScript对象(有一些限制)。例如:
const myMap = {"key-one": "abc", "key-two": 123};
await admin.firestore().collection("orders").add({
mappedData: myMap
});
只要地图的大小合适,上面的方法就可以正常工作。