Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/277.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/ant/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php Mongo$addToSet数组_Php_Mongodb_Aggregation Framework - Fatal编程技术网

Php Mongo$addToSet数组

Php Mongo$addToSet数组,php,mongodb,aggregation-framework,Php,Mongodb,Aggregation Framework,我有一个工作问题: $offenses = \App\LawCase::raw(function ($collection) { return $collection->aggregate([ [ '$match' => ['active' => true, 'type' => 'criminal', 'current_offense_literal'

我有一个工作问题:

$offenses = \App\LawCase::raw(function ($collection)  {
                return $collection->aggregate([
                    [
                        '$match' => ['active' => true, 'type' => 'criminal', 'current_offense_literal'=> ['$exists' => true]]
                    ],
                    [
                        '$group' => ['_id' => '$current_offense_category', 'offense_literals' => ['$addToSet' => '$current_offense_literal']]

                    ]
                ]);

            });
我只想为上面的addToSet添加一个附加值。例如,每个当前的\u冒犯\u文字也有一个当前的\u冒犯\u文字\u值,我想将其与当前的\u冒犯\u文字一起添加

我尝试的是:

$offenses = \App\LawCase::raw(function ($collection)  {
                return $collection->aggregate([
                    [
                        '$match' => ['active' => true, 'type' => 'criminal', 'current_offense_literal'=> ['$exists' => true]]
                    ],
                    [
                        '$group' => ['_id' => '$current_offense_category', 'offense_literals' => ['$addToSet' => ['$current_offense_literal'=>['$push'=> '$current_offense_literal_value']]]]

                    ]
                ]);

            });
但我得到了: 无法识别的表达式“$current\u offension\u literal”。

尝试执行此操作

$offenses = \App\LawCase::raw(function ($collection)  {
                return $collection->aggregate([
                    [
                        '$match' => ['active' => true, 'type' => 'criminal', 'current_offense_literal'=> ['$exists' => true]]
                    ],
                    [
                        '$group' => ['_id' => '$current_offense_category', 'offense_literals' => ['$addToSet' => ['current_offense_literal'=>'$current_offense_literal', 'current_offense_literal_value' =>'$current_offense_literal_value']]]

                    ]
                ]);

            });

非常感谢。就这样。