简体   繁体   中英

How to add data on a Push Key from firebase?

I am new to firebase and have been struggling the past days on something probably very simple.

Users are able to post. On top of that, they are also able to comment on posts. I would like to save each comment to their specific post that they have commented on.

Please check the below image for clarification.

RED: what I am trying to add in userPost's Push Keys

How can i access the userPost's Push Key to basically push more data in? I am working with JavaScript (ES6/React) and would be grateful for any help or tips!

Most likely the users can comment on a post in a screen where you display that post. In that case, you'll need to store the key of the post somewhere in that screen, and then use it to post the comment to the database.

The actual posting of the comment will look something like this:

var ref = firebase.database().ref("userPosts").ref(postId);
ref.child("comments").push("comment on post");

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