node.js - 使用节点 js 将 JSON 写入云 Firestore
问题描述
我一直在使用如下所示的嵌套 JSON 文件。我想将此 JSON 写入使用 node.js 的 Firestore 文档。
{
"title":"Sample tittle",
"icon":{
"type":"url/base64",
"url":"http://www.sample.com/icon.png"
},
"steps":{
"step1":{
"type":"play",
"url":"http://www.sample.com/"},
"step2":{
"type":"ask",
"url":"http://www.sample.com/ab14",
"Opts":["yes", "no"],
"next":[
{
"id":"step1",
"answer":"yes"
},
{
"id":"step3",
"answer":"no"
}
]
},
"step3":{
"type":"play",
"url":"http://www.sample.com/ase"}
}
}
解决方案
它不应该有任何问题。你可以在 GitHub 上找到很好的参考资料
https://github.com/googleapis/nodejs-firestore/blob/master/README.md
我已经使用它并且能够从您的 JSON 中创建文档,如下所示:
const {Firestore} = require('@google-cloud/firestore');
// Create a new client
const firestore = new Firestore();
async function quickstart() {
// Obtain a document reference.
const document = firestore.doc('test_collection/test_document');
// Enter new data into the document.
await document.set({
<your JSON here>
});
}
quickstart();
推荐阅读
- pytorch - CPU 使用率 99%+:当使用两个不同的 gpu 运行两个不同的 pytorch 程序时卡住了
- ansible - 用字符串替换 Ansible 列表的空索引
- google-assistant-sdk - 从另一个 python 文件调用 textinput.py
- python - 使用 QStackedLayout 在页面之间导航
- python - Wine 拒绝找到“ssl”python 模块
- python - 如何使用 Python-IDE Jupiter Notebook 更改条形图中 1 个特定条形的颜色
- compare - 回归调整 治疗效果估计
- kubernetes - 在虚拟机中访问 Kubernetes 集群
- dynamics-crm - Microsoft Dynamics API - 使用导航从实体获取字段
- google-apps-script - 使用仅来自另一个电子表格的一张表的数据创建一个新电子表格