📌  相关文章
📜  基于 id 数组的 Mongodb 计数 - TypeScript 代码示例

📅  最后修改于: 2022-03-11 14:48:24.733000             🧑  作者: Mango

代码示例3
db.collection.aggregate([
    { $unwind: "$connects" },

    // count all occurrences
    { "$group": { "_id": {skill: "$skill", parser_id: "$connects.parser_id"}, "count": { "$sum": 1 } }},

    // sum all occurrences and count distinct
    { "$group": { "_id": "$_id.skill", "quantity": { "$sum": 1 } }},

    // (optional) rename the '_id' attribute to 'skill'
    { $project: { 'skill': '$_id', 'quantity': 1, _id: 0 } }
])