thinkphp6 mongondb aggregate group实现分组查询
2022-11-24 11:10:29
176
{{single.collect_count}}
  1. thinkphp6 + mongondb 坑居多文档还不全只能读源码+猜想+测试终于探索出分组查询的实现方式
  2. 话不多说代码如下(其中$db应该是think\db\connector\Mongo 实例)
 $db=\think\facade\Db::connect('mongo');$command = ['aggregate' => '表名','pipeline' => [['$group' => ['_id' => '$聚合字段名', 'sum' => ['$sum' => 1]]],],'cursor' => new \stdClass()];$r=$db->cmd($command);halt($r);
回帖
全部回帖({{commentCount}})
{{item.user.nickname}} {{item.user.group_title}} {{item.friend_time}}
{{item.content}}
{{item.comment_content_show ? '取消' : '回复'}} 删除
回帖
{{reply.user.nickname}} {{reply.user.group_title}} {{reply.friend_time}}
{{reply.content}}
{{reply.comment_content_show ? '取消' : '回复'}} 删除
回帖
收起
没有更多啦~
{{commentLoading ? '加载中...' : '查看更多评论'}}