mongodb: finding the highest numeric value of a column

前端 未结 4 920
闹比i
闹比i 2020-12-19 06:34

I have MongoDB collection of documents containing several fields. One of the columns/fields should be numeric only, but some of these fields contain non-numerical (corrupt)

4条回答
  •  有刺的猬
    2020-12-19 07:32

    You can use aggregate function to get maximum number from collections like this.

    $data=$collection->aggregate(array
                        ( '$group'=> 
                            array('_id'=>'',
                                'age'=>array('$max'=>'$age'.)
                            )
                        )
                );
    

提交回复
热议问题