1

Is there a way to have an "empty" where query (that searches for anything).

Having

db.collection('skies').where('sky','==','blue')

right now I have to do

if (searchForAny){
  db.collection('skies').otherStuff();
}
else {
  db.collection('skies').where('sky','==','blue').otherStuff();
}

tzovourn
  • 1,293
  • 8
  • 18
Obiwahn
  • 2,677
  • 2
  • 26
  • 36

1 Answers1

1

Is there a way to have an "empty" where query (that searches for anything)

Yes it is. To solve that, simply remove the call to:

.where('sky','==','blue')

When you are using the where() function, you tell Firstore to return only those documents where the sky property holds the value of blue. If you need all documents, use only a reference to the skies collection, not a query.

Alex Mamo
  • 130,605
  • 17
  • 163
  • 193
  • As you can see, that is what I already do. But it is really cumbersome to have two different searches, since this is a rather frequent scenario. – Obiwahn Sep 16 '19 at 09:45
  • I'm sorry but I didn't understand you. I'm afraid you're not since you are calling `otherStuff()` (don't know it might be) and in the else part you are using for sure a query. And why do you say "it is really cumbersome to have two different searches"? If you don't need two, use a single one. – Alex Mamo Sep 16 '19 at 09:48