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

155
Views
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 answers
Answer question

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 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!