0

Hey there i am trying to get the random generated key of datasets from a firebase. like this:

projects ---12345 ---67890 ...

i just would like to get the key and safe it to another part in the Database.

I tried that: but it gives me everything under the node.

getKEY(){ 
    firebase.database().ref('project').once('value', function(snapshot) {
    console.log("Key" +  JSON.stringify(snapshot.val())  )       
 });
}

can some one help me out with that? How to get only the Key generated by firebase?

enter image description here

i would like to get these Keys and save it to another dataset but i don't know how to access them?

Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807
NeunNatter
  • 87
  • 1
  • 9
  • There is no way through the JavaScript SDK to get the keys without also getting the data under it. See https://stackoverflow.com/questions/32442546/firebase-retrieve-child-keys-but-not-values – Frank van Puffelen May 20 '18 at 20:58

1 Answers1

1

Try the following:

getKEY(){ 
firebase.database().ref('project').once('value', function(snapshot) {
snapshot.forEach(function(child) {
var keys=child.key;   
  });   
 });
}

more info here:

key property

Peter Haddad
  • 78,874
  • 25
  • 140
  • 134