how to use aggregate function in meteor

前端 未结 4 1274
悲哀的现实
悲哀的现实 2020-12-07 01:46

I\'m working on the following document

{
\"_id\" : 12,
\"firstName\" : \"wer\",
\"People\" : [ 
    {
        \"uuid\" : \"123\",
        \"name\" : \"sugun\         


        
4条回答
  •  暗喜
    暗喜 (楼主)
    2020-12-07 02:17

    By using rawCollection you can pass in the same pipeline that you've been using in your mongo shell.

    There is no need to install a third-party package to do this.

    const stats = await MyCollection.rawCollection()
        .aggregate([
          {$match: {_id: 12}}, 
          {$unwind: "$People"}, 
          {$unwind: "$People.person"}, 
          {$match: {"People.uuid": "123", "People.person.uuid" : "add32"}}
        ])
        .toArray();
    

提交回复
热议问题