我不管,反正我最萌~
BSON field 'count.query' is the wrong type 'array', expected type 'object'
。在think-mongo版本,vendor/topthink/think-mongo/src/Builder.php文件中,parseWhere
方法在做过滤条件初始化的时候,没有考虑周全,将数据类型定义为了数组。
在parseWhere
方法返回的时候做一个判断,如果$filter
为空,就重新定义为stdClass
对象。
修改的方法就是在return前添加如下代码:
// 修改代码 开始
if (empty($filter)){ // 返回空对象
return new \stdClass();
}
// 修改代码 结束
完整parseWhere
方法参考以下代码:
/**
* 生成查询过滤条件
* @access public
* @param Query $query 查询对象
* @param mixed $where
* @return array
*/
public function parseWhere(Query $query, $where)
{
if (empty($where)) {
$where = [];
}
$filter = [];
foreach ($where as $logic => $val) {
foreach ($val as $field => $value) {
if (is_array($value)) {
if (key($value) !== 0) {
throw new Exception('where express error:' . var_export($value, true));
}
$field = array_shift($value);
} elseif (!($value instanceof \Closure)) {
throw new Exception('where express error:' . var_export($value, true));
}
if ($value instanceof \Closure) {
// 使用闭包查询
$query = new Query($this->connection);
call_user_func_array($value, [ & $query]);
$filter[$logic][] = $this->parseWhere($query, $query->getOptions('where'));
} else {
if (strpos($field, '|')) {
// 不同字段使用相同查询条件(OR)
$array = explode('|', $field);
foreach ($array as $k) {
$filter['$or'][] = $this->parseWhereItem($query, $k, $value);
}
} elseif (strpos($field, '&')) {
// 不同字段使用相同查询条件(AND)
$array = explode('&', $field);
foreach ($array as $k) {
$filter['$and'][] = $this->parseWhereItem($query, $k, $value);
}
} else {
// 对字段使用表达式查询
$field = is_string($field) ? $field : '';
$filter[$logic][] = $this->parseWhereItem($query, $field, $value);
}
}
}
}
$options = $query->getOptions();
if (!empty($options['soft_delete'])) {
// 附加软删除条件
list($field, $condition) = $options['soft_delete'];
$filter['$and'][] = $this->parseWhereItem($query, $field, $condition);
}
// 修改代码 开始
if (empty($filter)){ // 返回空对象
return new \stdClass();
}
// 修改代码 结束
return $filter;
}
昵称:zqifa
站龄: 3年2个月
博客持续完善ing,敬请期待...
打滚求打赏(๑ ̄ ̫  ̄๑)
❤此处弱弱求打赏~~万一有好心人呢~~❤
支付宝酱
微信酱
Copyright © zqifa 联系方式:z___qf@163.com