Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

94
Views
read messages from realtime databse in firebase with javascript

i want to read messagea from realtime database in firebase with vue or javascript in quasar framework

my collection name in db is messages that have this strtucture: ******************************************* my db structure*******

messages
         -N4zbIt0Ey6Bix54f5SE
             content: "Hi"
             fromId: "nTTcnND2y6OHUBVO2GxHoBFwQf32"
             timestamp: 1655703420767
             toId: "0FXpksPdL4OAf9KAXx9B0R6nzmh2"
             type: 1
        -N4zbIt0Ey6Bix54f5SE
             content: "Hi,HOW ARE YOU"
             fromId: "0FXpksPdL4OAf9KAXx9B0R6nzmh2"             
             timestamp: 1655703448111
             toId: "nTTcnND2y6OHUBVO2GxHoBFwQf32"
             type: 1

do you know how i query firebase to getmessages?? ithis is for save in state with Vuex

firebaseGetMessages({ commit, state }, otherUserId) {
    let userId = state.userDetails.userId
    messagesRef = firebaseDb.ref('messages/' + fromId + '/' + toId)
    messagesRef.on('child_added', snapshot => {
        let messageDetails = snapshot.val()
        let messageId = snapshot.key
        commit('addMessage', {
            messageId,
            messageDetails
        })
    })

i think this code is wrong please help me if you have any experince with firebase

i am not familar with realtime-databse and query in fcm but familar with mongodb and sql server database i think that firebase has some function to read message!!! is it n't???

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Your code indeed does not match the data structure that you shared.

Your code expects this structure:

messages: {
  "uidOfSender": {
    "uidOfRecipient": {
      ...
    }
  }
}

While your data structure has the UIDs of the sender and receiver as properties on each message in a flat list.

Worse: there is no way to get the messages between a sender and receiver from your current structure, as Firebase Realtime Database queries can only filter on one property. See my answer here for more on that: Query based on multiple where clauses in Firebase

The data structure in general looks like a 1:1 translation of what you'd do in a relation database, which is often not a great starting point when modeling data for a NoSQL database. What you'll want to do is create a different data structure where you set up a sort-of "chat room" for each pair of users, as I've shown here: Best way to manage Chat channels in Firebase

I also recommend reading NoSQL data modeling and watching Firebase for SQL developers.

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!