How do I define the following MongoDB aggregate query in mongoose:
db.contacts.aggregate([{$group: { \"_id\": { code: \"$Code\", name: \"$Name\" } } }])
<
Try this
Contacts.aggregate({$group: { "_id": { code: "$Code", name: "$Name" } } }, function(err, contacts) {
...
});
Or, with $match
if you need this AgencyTranslation: /^BROADCASTING/
condition
Contacts.aggregate([
{ $match : { AgencyTranslation: /^BROADCASTING/ } },
{ $group: { "_id": { code: "$Code", name: "$Name" } } }
], function(err, contacts) {
// ...
});