0

Image of database

enter image description here

So that's my database, and I wanna collect all alamat from all record i have, diki and rizky

Here is my code

var optList = {"method" : "get"};
var recordName = "diki";

var rsltList = UrlFetchApp.fetch("https://martabak-bot.firebaseio.com/" + recordName + "/.json", optList );
var importdb = JSON.parse(rsltList);
var posting= (importdb.alamat);

So far I can collect Diki's alamat and put it on posting variable.

So if I wanna collect all alamat, what should I do? Based on this question : How to get all child's data in firebase database?

Is this datasnapshot works for me too? But I don't see it finished with stored to a variable.

Thanks for the help and answer, I really a beginner in JS. Thank you.

KENdi
  • 7,576
  • 2
  • 16
  • 31
SADmiral
  • 41
  • 4
  • Firebase documentation talks about [collections of documents](https://firebase.google.com/docs/firestore/data-model) and how to [filter by keys](https://firebase.google.com/docs/database/rest/retrieve-data#filtering-by-key) ; simplying `fetch()`ing `https://martabak-bot.firebaseio.com/.json` will return your full DB – sinaraheneba Jun 07 '19 at 05:30
  • @Altigraph actually since the day u comment this and till now i read it again and again. and doing testing but it looks like the answer of my question :( – SADmiral Jun 14 '19 at 13:03
  • how to up this question.. please i need some help :( its a weeks since i ask this – SADmiral Jun 14 '19 at 13:05

1 Answers1

0

I think you should denormalizing your data, for example to create something like

martabak-bot/
  alamat/
    diki: Tiban
    rizki: Taman
    ...

so you can retrieve them with

curl 'https://martabak-bot.firebaseio.com/alamat.json?print=pretty'

see Denormalizing Your Data is Normal

Itang Sanjana
  • 649
  • 5
  • 8