I have been working with a nested JSON file as given below. I want to write this JSON to a firestore document using node.js.
{
"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"}
}
}
There shouldn't be any problem with it. You can find nice reference on GitHub
https://github.com/googleapis/nodejs-firestore/blob/master/README.md
I have used it and was able to create document from your JSON like this:
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();
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.