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

203
Visualizações
Query an array in firestore

Im trying to implement my mobile app with local notifications. To achieve that i have a function that listens to changes made in firestore if a notification is added the notification fires to the user. Here is the code i have :

 const deviceId = Constants.deviceId;

    Firebase.firestore().collection('notifications').where('user_reads', '!=', [deviceId]).onSnapshot(snapshot => {
    const {stat} = this.context;

      snapshot.docChanges().forEach(change => {
        const doc = change.doc.data();

        if (change.type === 'added') {
          console.log(change.doc.data(), 'added');

          //handle notification recived
          Notifications.addNotificationResponseReceivedListener(async response => {
            console.log(response.notification.request.identifier);

            //update read status in notification table and save uid of user who read notification
            Firebase.firestore().collection('notifications').doc(change.doc.id).update({
              user_reads: firebase.firestore.FieldValue.arrayUnion(deviceId),
              read: true,
            });

            //send user to the new post
            RootNavigation.navigate(t('SinglePost'), { id:  response.notification.request.content.data.data });
          });
        } else if (change.type === 'modified') {
          console.log(change.doc.data(), 'modified');
        }

        sendPushNotification(doc.title, doc.body, doc.postId);
      })
    });

How can i make the firestore to stop listening to changes. I save deviceId in an array in firestore. How can i condition this array to check if the the specific deviceId exists to stop listening to changes. Here is the screen-shot enter image description here

about 4 years ago · Juan Pablo Isaza
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