将过滤器放入 firestore 的 livewire 搜索中
Putting filters into a livewire search from firestore
使用 Cloud Firestore,如何在单个查询中使用多个 where 语句?我正在抛出 BadRequestException(每个查询只允许一个 'NOT_EQUAL'、'NOT_IN'、'IS_NOT_NAN' 或 'IS_NOT_NULL' 过滤器。)
$query = $this->db->collection('accounts');
$query = $this->filterStatus && $this->filterStatus != -1 ? $query->where('status', '=', $this->filterStatus) : $query->where('status', '!=', '0');
$query = $this->filterRisk && $this->filterRisk != -1 ? $query->where('risk_level', '=', $this->filterRisk) : $query->where('risk_level', '!=', '0');
$accounts = $query->documents();
也不确定这是否是在 firebase 代码中包装 where 代码的最佳方式
问题不在于您有多个条件,而在于您使用了不允许的条件组合。正如 query limitations 上的错误消息和文档所说:
In a compound query, range (<, <=, >, >=) and not equals (!=, not-in) comparisons must all filter on the same field.
并且在您的代码中您尝试同时执行 $query->where('status', '!=', '0')
和 $query->where('risk_level', '!=', '0')
,这不符合该限制。
您必须对数据库执行其中一个条件,并在您的应用程序代码中执行额外的过滤。
使用 Cloud Firestore,如何在单个查询中使用多个 where 语句?我正在抛出 BadRequestException(每个查询只允许一个 'NOT_EQUAL'、'NOT_IN'、'IS_NOT_NAN' 或 'IS_NOT_NULL' 过滤器。)
$query = $this->db->collection('accounts');
$query = $this->filterStatus && $this->filterStatus != -1 ? $query->where('status', '=', $this->filterStatus) : $query->where('status', '!=', '0');
$query = $this->filterRisk && $this->filterRisk != -1 ? $query->where('risk_level', '=', $this->filterRisk) : $query->where('risk_level', '!=', '0');
$accounts = $query->documents();
也不确定这是否是在 firebase 代码中包装 where 代码的最佳方式
问题不在于您有多个条件,而在于您使用了不允许的条件组合。正如 query limitations 上的错误消息和文档所说:
In a compound query, range (<, <=, >, >=) and not equals (!=, not-in) comparisons must all filter on the same field.
并且在您的代码中您尝试同时执行 $query->where('status', '!=', '0')
和 $query->where('risk_level', '!=', '0')
,这不符合该限制。
您必须对数据库执行其中一个条件,并在您的应用程序代码中执行额外的过滤。