I am facing a challenge where I need to transfer the following JSON data from my local storage to Firebase Firestore:
guides: [
{
"id":0,
"name":"name0",
"sources":[
{
"type":"s3",
"url":"https://s3.amazonaws.com/xxxx/file0.mp3"
}
]
},
{
"id":1,
"name":"name1",
"sources":[
{
"type":"s3",
"url":"https://s3.amazonaws.com/xxxx/file1.mp3"
}
]
}
]
I am looking for the most effective way to store the "sources" data so that when searching for "guides" (using firebase cloud functions), the source list can be retrieved without having to make separate search queries for each element of sources.
In trying to work with Firebase Firestore, I encountered the issue where the array type does not allow a list of objects and using a "reference" returns the structure and settings of the referenced document.
function getGuides(guideId,response){
db.collection('guides')
.where('id', '==', guideId).get()
.then(snapshot => {
let guideDoc = snapshot.docs.map( doc => {
return doc.data()
})
return guideDoc;
})