Google cloud platform 如何搜索;任何;使用firestore中的.where()?

Google cloud platform 如何搜索;任何;使用firestore中的.where()?,google-cloud-platform,google-cloud-firestore,Google Cloud Platform,Google Cloud Firestore,有没有一种方法可以让where查询“空”(搜索任何内容) 拥有 db.collection('skies')。其中('sky','=','blue') 现在我必须做 if (searchForAny){ db.collection('skies').otherStuff(); } else { db.collection('skies').where('sky','==','blue').otherStuff(); } 有没有一种方法可以让where查询“空”(搜索任何内容) 是的。

有没有一种方法可以让where查询“空”(搜索任何内容)

拥有

db.collection('skies')。其中('sky','=','blue')

现在我必须做

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

有没有一种方法可以让where查询“空”(搜索任何内容)

是的。要解决此问题,只需删除以下调用:

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

当您使用
where()
函数时,您会告诉Firstore仅返回
sky
属性值为
blue
的文档。如果您需要所有文档,请仅使用对
skies
集合的引用,而不是查询。

如您所见,这是我已经做过的。但是有两个不同的搜索是非常麻烦的,因为这是一个相当常见的情况。对不起,我不明白你的意思。恐怕您没有,因为您正在调用
otherStuff()
(不知道可能是这样),并且在else部分您肯定正在使用一个查询。为什么你会说“有两个不同的搜索真的很麻烦”?如果你不需要两个,就用一个。嗨,奥比瓦恩!我能帮你了解其他信息吗?如果你认为我的回答对你有帮助,请考虑接受它。✔️). 我真的很感激。谢谢!