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

168
Visualizações
How to implement conditions with boolean operators "and" and "or"?

How can I implement a condition using boolean operators and and or using firestore?

An example of what I want to do:

  this.itemsCollection = this.afs.collection<Message>('messages', ref => {
    let query: firebase.default.firestore.CollectionReference | firebase.default.firestore.Query = ref;
    query = ((query.where('senderId', '==', this._cs.senderId || '') && query.where('receiverId', '==', this.receiverId || ''))
      || (query.where('receiverId', '==', this._cs.senderId || '') && query.where('senderId', '==', this.receiverId || '')))
    return query;
  })
  this.items = this.itemsCollection.valueChanges();
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

There is no option to do an OR on different fields in Firestore. You will have to execute multiple queries for this, and then merge the results in your application code.

To check an OR for multiple values on a single field is called an in condition in Firestore, and can be done with:

query.where('senderId', 'in', [this._cs.senderId, '']) 

The empty string here must literally exist in the document for the to match the condition. There is no way to filter for documents where senderId doesn't exist, as documents without a value for that field simply won't exist in the index that Firestore created for senderId.

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