We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
think-mongo/src/Builder.php
Line 525 in 4e01004
应该单独判断“ ['$group' => ['_id' => $group, 'aggregate' => ['$' . $fun => '$' . $field]]],”中的$fun,如果时统计,可以直接设置为['$sum' => 1],否则当field字段为非数字时无法统计。
我的解决方法是: if ($fun == 'count') { $pipeline = [ ['$match' => (object) $this->parseWhere($query, $options['where'])], ['$group' => ['_id' => $group, 'aggregate' => ['$sum' => 1]]], ]; } else { $pipeline = [ ['$match' => (object) $this->parseWhere($query, $options['where'])], ['$group' => ['_id' => $group, 'aggregate' => ['$' . $fun => '$' . $field]]], ]; }
The text was updated successfully, but these errors were encountered:
No branches or pull requests
think-mongo/src/Builder.php
Line 525 in 4e01004
应该单独判断“ ['$group' => ['_id' => $group, 'aggregate' => ['$' . $fun => '$' . $field]]],”中的$fun,如果时统计,可以直接设置为['$sum' => 1],否则当field字段为非数字时无法统计。
我的解决方法是:
if ($fun == 'count') {
$pipeline = [
['$match' => (object) $this->parseWhere($query, $options['where'])],
['$group' => ['_id' => $group, 'aggregate' => ['$sum' => 1]]],
];
} else {
$pipeline = [
['$match' => (object) $this->parseWhere($query, $options['where'])],
['$group' => ['_id' => $group, 'aggregate' => ['$' . $fun => '$' . $field]]],
];
}
The text was updated successfully, but these errors were encountered: