简体   繁体   中英

How to custom Key Name in firebase

i am need custom key name in firebase database this my code

  firebase.database().ref("chat").child('aaa')
    firebaseRef.push({
        text : 'bbb'
    })

result enter image description here

To have it like your image you can do this, just add a new child where to store your text and remove .push since that will push randomly generated value to store the text

   firebase.database().ref("chat").child('aaa').child('ccc')
        firebaseRef.set({
         text : 'bbb'
});

Yes, you can store data under custom key name (however, you'll have to verify the uniqueness of that key yourself).
Your code will look something like -

var firebaseRef = firebase.database().ref("chat").child('aaa').child('ccc');
firebaseRef.set({
   text : 'bbb'
});

You can further read up on this at Firebase Realtime database - Read and Write .
This will give you the structure that you want (as per your image).

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM