How to use Aggregate in mongoose

后端 未结 1 1571
北恋
北恋 2021-02-13 15:37

How do I define the following MongoDB aggregate query in mongoose:

db.contacts.aggregate([{$group: { \"_id\": { code: \"$Code\", name: \"$Name\" } } }])
<         


        
相关标签:
1条回答
  • 2021-02-13 16:22

    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) {
      // ...
    });
    
    0 讨论(0)
提交回复
热议问题