Uploaded image for project: 'Go Driver'
  1. Go Driver
  2. GODRIVER-1228

Use both $group and $match don't work

    • Type: Icon: Task Task
    • Resolution: Done
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: 1.0.3
    • Component/s: BSON
    • Labels:
      None
    • Environment:
      macOS Mojave 10.14.2

      aggQuery := []bson.M{{
         "$group": bson.M{
            "_id": "$created_at",
            "play_sum": bson.M{
               "$sum": "$play_num",
            },
            "comment_sum": bson.M{
               "$sum": "$comment_num",
            },
         },
         "$match": []bson.M{{
            "vid": bson.M{
               "$in": bson.A{
                  "...",
                  "....",
               },
            },
         }},
      }}
      
      cursor, err := myCollection.Aggregate(ctx, aggQuery)

      i try it not work, error message:

      2019/08/11 18:56:52 (Location40323) A pipeline stage specification object must contain exactly one field.
      

       

      but i replace `aggQuery`:

      aggQuery := []bson.M{{
         "$group": bson.M{
            "_id": "$created_at",
            "play_sum": bson.M{
               "$sum": "$play_num",
            },
            "comment_sum": bson.M{
               "$sum": "$comment_num",
            },
         },
      }}

      is working.

            Assignee:
            Unassigned Unassigned
            Reporter:
            wsadwsadqe@hotmail.com cc vokia
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: