Running raw aggregations #2079
              
                Unanswered
              
          
                  
                    
                      canavci2016
                    
                  
                
                  asked this question in
                General
              
            Replies: 1 comment
-
| Hi, I had the same question when I startet working with this package. So even if the question was asked long time ago, maybe the answer is helpfull for other beginners. You can use the 'raw()' function like this giving a closure as argument which returns your aggregation: $results = $this->model_name::raw(function ($collection) { You can also pass your complex query to the closure: $query = ['some complex query ...']; $results = $this->model_name::raw(function ($collection) use ($query) { | 
Beta Was this translation helpful? Give feedback.
                  
                    0 replies
                  
                
            
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment
  
        
    
Uh oh!
There was an error while loading. Please reload this page.
-
Hi,
how can I run a raw aggregations following
$collection->aggregate([
['$unwind' => ['path' => '$accommodation_types', 'preserveNullAndEmptyArrays' => true]],
['$match' => ['accommodation_types' => ['$exists' => true]]],
['$match' => ['_id' => new \MongoDB\BSON\ObjectId('5eb149b6e0b2555e66013e26')]],
['$group' => ['_id' => '$accommodation_types', 'count' => ['$sum' => 1]]],
['$addFields' => ['type' => '$_id']],
]);
Beta Was this translation helpful? Give feedback.
All reactions