Javascript 如何将数组映射添加到firestore数据库?
我可以通过节点将json数据添加到firestore数据库,如下面的json数据Javascript 如何将数组映射添加到firestore数据库?,javascript,node.js,json,firebase,google-cloud-firestore,Javascript,Node.js,Json,Firebase,Google Cloud Firestore,我可以通过节点将json数据添加到firestore数据库,如下面的json数据 [ { "itemID": "NOODLES_V_101", "itemName": "Hakka Noodles", "itemPriceHalf": 80, "itemPriceFull": 130, "hasImage": fa
[
{
"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数组映射,我应该怎么做?
我想要的数组映射类型如下面的屏幕截图所示
如果需要更多信息,请告诉我
下面是我用来向firestore添加json数据的代码
forEach(函数(文件){
var lastDotIndex=file.lastIndexOf(“.”)
}));
我有json文件,这些文件通过上面的代码添加为firestore数据,您需要的只是一个对象数组,类似于上面所示
firebase
.collection("your-collection")
.doc("your-document")
.set({
ids: [
{ id: "1" },
{ id: "2" }
]
})
道格,我按你说的做了尝试,但没有成功,请检查我用更多代码信息编辑的问题。你能试着用
.set()
而不是.add()
。使用add()
将创建一个自动生成ID的新文档。
firebase
.collection("your-collection")
.doc("your-document")
.set({
ids: [
{ id: "1" },
{ id: "2" }
]
})