Search
 
SCRIPT & CODE EXAMPLE
 

PHP

group by count mongodb laravel

<?php 

$category_ids = []; //categories goes here

$results = Post::raw(function($collection) use ($category_ids) {
    return $collection->aggregate([
        //where in...
        [
            '$match' => [
                'category_id' => ['$in' => $category_ids]
            ]       
        ],  
        [   
            '$group' => [
                '_id' => '$user_id',
                'count' => ['$sum' => 1]   
            ]   
        ],  
        [   
            '$sort' => ['count' => -1]   
        ],  
        [   
            '$limit' => 10
        ],  
    ]); 
});
Comment

PREVIOUS NEXT
Code Example
Php :: upload image with watermark in codeigniter 
Php :: functions.php not working wordpress 
Php :: dompdf php 8 
Php :: laravel get route 
Php :: Add to cart, link to product page 
Php :: wordpress theme basics including CSS and js 
Php :: month php written out 
Php :: curlopt_postfields php example 
Php :: PHP If If Else Else Statement 
Php :: php $_files 
Php :: laravel use npm package 
Php :: how to check if page opened from mobile or desktop 
Php :: php pass function as callback 
Php :: laravel telescope tutorial 
Php :: mysql gone away error in php 
Php :: page.php woocommerce 
Php :: Export Database Records to CSV 
Php :: iframe site bi link laravel 
Php :: access paginator object attribute in laravel 
Php :: define function in php 
Php :: str_replace(): Passing null to parameter #3 ($subject) of type array|string is deprecated Filename: core/Output.php 
Php :: route list laravel 8 
Php :: show widget using the shortcode from php 
Php :: Remove White Space At Sides 
Php :: laravel withValidator 
Php :: How to add .active class to active menu item 
Php :: check box with value in php 
Php :: adminlte con laravel 8 
Php :: Laravel DB facade relations 
Php :: laravel dingo api response 
ADD CONTENT
Topic
Content
Source link
Name
5+9 =