【发布时间】:2020-12-02 08:46:47
【问题描述】:
我有一个包含大量字段的“用户”的 firebase 数据库。我还有一个过滤器,它对这些字段执行查询并返回过滤后的用户。问题是查询可以获取位置值为空字符串的对象,如果值为"",我想忽略.where 代码行但执行其他代码。我'我尝试将值转换为undefined 和null,但undefined 抛出错误并且null 不显示任何用户。
exports.filterUsers = (req, res) => {
db.collection("users")
.where("gender", "==", req.body.gender)
.where("age", "<=", req.body.maxAge)
.where("age", ">=", req.body.minAge)
.where("location", "==", req.body.location)
.get()
【问题讨论】:
-
如果不需要 where 子句,可以直接选择不添加,如副本所示。
标签: javascript firebase google-cloud-firestore