2015-09-04

MongoDB - How to aggregate distinct children field into a single field array ($addToSet)

db.COLLECTION_NAME_HERE.aggregate([
    {$group:
        {
            _id: "$FIELD_TO_GROUP_BY_NAME_HERE"
            , AGGREGATED_FIELD_ALIAS : { $addToSet : "$FIELD_TO_AGGREGATE" }
        }
    }
]);

No comments:

Post a Comment