Mongodb(一)aggregate聚合函数的用法

#命令行操作

db.book_info.aggregate({"$match":{"ObjectType":"3","Language":"0","EndTime":{"$gt":时间}}},{"$sort":{"UserId":1}},{"$limit":5})

#PHP7以下操作mongodb

cs;            // 选择一个数据库
    $collection = $db->cs;// 选择集合
    $pipeline = array(
        array(
            '$match'=>array(
                'ObjectType'=>array(
                    '$eq' =>'3'
                ),
                'Language'=>array(
                    '$eq'=>'0'
                ),
                'EndTime' =>array(
                    '$gt'=> date('Y-m-d h:i:s',time())
                ),
            ),
        ),array(
            '$sort'=>array(
                'UserId'=>1
            )
        ),
        array(
            '$limit'=>5
        )
    );
$cursor = $collection->aggregate($pipeline);
foreach ($cursor as $document) {
       $events[] = $document;
}

aggregate聚合函数的参数
https://blog.csdn.net/qq_39263663/article/details/80459833
其它函数的用法
http://lib.csdn.net/article/mongodb/51421
#推荐观看 Mongodb的菜鸟教程

你可能感兴趣的:(数据库)