Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

95
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda