Doubt how to "read" data in firebase-database

Asked

Viewed 390 times

1

Assuming I have this structure in the bank

    
userId : {
  Messages : {
   SenderID : {
      PushID: {
         "msg": "Mensagem"
      }
   }
}

I’m using this code to "read" everything inside the "userid"

dbRef.child(user.uid + "/Messages").on("value", function(snap){
                        
                        obj.html(JSON.stringify(snap.val(), null, 3));
                    });

but the return I need is just the "msg": "message"

would like to know how to return only what I need, can anyone help me ? From now on

  • What is the context? Do you want that specific message or all the messages from UserId?

  • Good evening Guilherme, All messages within Senderid. that part of the bank would be a chat between two users

  • I believe I should review the structure of the bank, personally I would change its structure, it is recommended to avoid the use of many chained nodes

  • Can you give me an idea of structure ?

  • In itself documentation an example chat is used to explain how to structure the database. I would transform Senderid and Userid into two Pushid fields

  • Perfect my friend , I took a look at the link of the documentation you sent there , and solved , I will change the structure and the way to store the msgs , honestly this way I was trying to do would have to replicate a lot of data , and with this idea there of the documentation I store everything in a single place where only the two users can read , thanks friend

  • If you have any difficulty in doing something edit the question with your question and let us know in the comments :)

Show 2 more comments
No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.