【发布时间】:2021-02-07 17:10:26
【问题描述】:
我可以通过节点将 json 数据添加到 firestore 数据库,如下 json 数据
[
{
"itemID": "NOODLES_V_101",
"itemName": "Hakka Noodles",
"itemPriceHalf": 80,
"itemPriceFull": 130,
"hasImage": false,
"itemCategory": "noodles_v",
"itemType": "v"
},
{
"itemID": "NOODLES_V_102",
"itemName": "Shezwan Noodles",
"itemPriceHalf": 80,
"itemPriceFull": 130,
"hasImage": false,
"itemCategory": "noodles_v",
"itemType": "v"
},
]
我想通过 JSON 添加 firestore 数组映射,我应该怎么做? 我想要的数组映射类型如下面的截图所示
如果需要更多信息,请告诉我
我用来将 json 数据添加到 firestore 的代码如下 files.forEach(函数(文件){ var lastDotIndex = file.lastIndexOf(".");
var menu = require("./files/" + file);
menu.forEach(function(obj) {
firestore
.collection(file.substring(0, lastDotIndex))
.doc(obj.itemID)
.set(obj)
.then(function(docRef) {
console.log("Document written");
})
.catch(function(error) {
console.error("Error adding document: ", error);
});
});
}); 我有 json 文件,这些文件正在通过上述代码添加为 firestore 数据
【问题讨论】:
标签: javascript node.js json firebase google-cloud-firestore