Search code examples
javascriptfirebasefirebase-realtime-database

How to retrive document ID from firebase(not firestrore)?


How to get document Id from realtime database,not firestore? I need to get list of document ids via javascript


Solution

  • Set configuration and initialize firebase:

      var firebaseConfig = {
          //You can get the necessary information in you project console
      };
      // Initialize Firebase
      firebase.initializeApp(firebaseConfig);
    

    This will give you the keys of your reference children:

    var myRef = firebase.database().ref(//path to you data);
    var keys = [];  
    myRef.once("value", function(snapshot){
      documents=Object.keys(snapshot.val());
      for(d in documents){
        keys.push(documents[d]);
      }
    }