Mongodb 分组查询例子

db.tblCard.aggregate([
    {
        $match: {
            "sNo": {
                "$exists": true
            },
            "pNo": {
                "$exists": true
            },
            "pEffDate": {
                "$gte": ISODate("2017-01-01T00:00:00.000+0800"),
                "$lte": ISODate("2017-05-01T08:00:00.000+0800")
            }
        }
    },
    {
        $group: {
            "_id": {
                "pNo": "$pNo",
                "bNo": "$bNo"
            },
            "count": {
                "$sum": 1
            }
        }
    },
    {
        $out: "tblResult"//将结果输出到数据集中
    }
]);

posted @ 2017-06-06 11:19  94cool  阅读(266)  评论(0编辑  收藏  举报