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

157
Views
How can I compare data from two different collections?

I am retrieving a certain document from the collection products and I wanted to compare it to another collection of categories

Specific document from Product collection:

enter image description here

Category collection:

There might be some documents that does not have options, they could be determined by the field value. If it has a string yes, then it does have options. Otherwise, it will be a no.

enter image description here enter image description here

I can already display the specific document from the product collection. I used map to display the products.

Inside that map, I wanted to have a conditional statement that will display all of the options if the current product's category matches with any of the document in the collection categories that has options in it.

For example, the current product is Shirt with a category of S-L. In the category collection, the S-L does have options.

And if the current product does not have any options, then it will just display "No options"

What I did:

 {product &&
              product.map((prod, index) => (
                <li>{prod.cat}</li>
                <li>{prod.prodName}</li>
                  //if the current product matches with any of the document in the collection category, then show the options, else show "no options"
                   {category &&
                  category.map((c, index) => (
                    <>
                      <li>{c.cat}</li>

                      {c.cat === prod.cat ? <>1</> : <>2</>}
                    </>
                  ))}
              ))}

How can I do this?

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

0

It looks like you have built a relation based schema and you would like to perform an outer join using conditional statements. The map function does not support conditional statements as its role is to transform entities. As shared that Firestore does not support join on collections as that is a document storage type of database.

To help you get started, the Java Script allows to create an if statement in the body of map function, for details please check

  • How to use if within a map return?

The alternative strategy for you would be to keep the data within the main structure (product) and then fetch all data by single request and present them accordingly or you may want is to write code to read every document in every collection that would need a comparison, and also perform that comparison with the documents in memory. Below I share some resources that might be helpful to understand how data should be structured in Firestore.

  • https://www.youtube.com/watch?v=haMOUb3KVSo
  • https://www.youtube.com/watch?v=jm66TSlVtcc
  • https://www.youtube.com/watch?v=o7d5Zeic63s
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!