内容纲要

按数组长度排序

Question.aggregate(
    [
        { "$project": {
            "title": 1,
            "content": 1,
            "created": 1,
            "updated": 1,
            "author": 1,
            "answers": 1,
            "length": { "$size": "$answers" }
        }},
        { "$sort": { "length": -1 } },
        { "$limit": 5 }
    ],
    function(err,results) {
        // results in here
    }
)
    cursor = login_records.aggregate([   
         { 
            "$match" : {
                "is_bind_ip" : False
            }
        }, 
        { 
            "$group" : {
                "_id" : {
                    "error" : "$error"
                }, 
                "count" : {
                    "$sum" : 1
                }
            }
        }, 
        { 
            "$sort" : {
                "count" : -1
            }
        },
        { "$out" : "first_error" }
    ], allowDiskUse=True)

参考

发表评论

电子邮件地址不会被公开。 必填项已用*标注