久久久久久久视色,久久电影免费精品,中文亚洲欧美乱码在线观看,在线免费播放AV片

<center id="vfaef"><input id="vfaef"><table id="vfaef"></table></input></center>

    <p id="vfaef"><kbd id="vfaef"></kbd></p>

    
    
    <pre id="vfaef"><u id="vfaef"></u></pre>

      <thead id="vfaef"><input id="vfaef"></input></thead>

    1. 站長資訊網(wǎng)
      最全最豐富的資訊網(wǎng)站

      關(guān)于Laravel使用MongoDB復雜的查詢

      下面由Laravel教程欄目給大家介紹關(guān)于Laravel使用MongoDB復雜的查詢,希望對需要的朋友有所幫助!

      關(guān)于Laravel使用MongoDB復雜的查詢

      簡介:在使用Laravel中如果要進行復雜的查詢,那么通過模型中的函數(shù)來查詢是不行的,所以本文主要記錄如何通過aggregate來進行復雜的查詢。

      Laravel使用的mongodb庫

      composer require jenssegers/mongodb

      分組查詢

      用戶表中包含
      city_id:城市ID
      sex:性別,1男,2女
      age:年齡
      需要通過城市ID分組查詢性別未男女的平均值,那么在laravel中實現(xiàn)如下,其他框架也大同小異

      $cityId = 1;//城市ID $count = UserModel::query()->raw(function ($collection) use ($cityId) {     $aggregate = [];     $aggregate[]['$match'] = [         'city_id' => intval($city_id),//過濾城市         'sex' => ['$in' => [1,2]],//過濾性別     ];     $aggregate[]['$group'] = [         '_id' => '$sex',//更具性別進行分組         'avg_age' => [             '$avg' => '$age',//查詢年齡平均值         ]     ];     //這里還可以繼續(xù)添加各種條件     return $collection->aggregate($aggregate)->toArray(); });

      贊(0)
      分享到: 更多 (0)
      網(wǎng)站地圖   滬ICP備18035694號-2    滬公網(wǎng)安備31011702889846號