Answers for "count entries in addtoset"

0

count entries in addtoset

db.collection.aggregate([{
    $group: {
    _id: {
        organization: "$user.organization"
    },
    machineId: {
        "$addToSet": "$user.machineId"
    }
    }
}, {
    $project: {
    "organization": "$_id.organization",
    "machineId": 1,
    "_id": 0,
    "size": {
        $size: "$machineId"
    }
    }
}])
Posted by: Guest on April-30-2022

Code answers related to "count entries in addtoset"

Browse Popular Code Answers by Language