Uploaded image for project: 'C# Driver'
  1. C# Driver
  2. CSHARP-1173

Aggregation Framework needs to support $addToSet and $push inside a Group expression tree

    XMLWordPrintable

    Details

    • Type: New Feature
    • Status: Closed
    • Priority: Major - P3
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 2.0
    • Component/s: None
    • Labels:
      None
    • Sprint:
      C# Sprint 14

      Description

      Currently, the only 2 accumulators we do not support are $push and $addToSet.

      We could implement these in a simple manner with the following syntax.

      For $push:

      { $group: {_id: "$State", Cities: { $push: "$City" } } }

      .Group(x => x.State, g => new 
      { 
        _id = g.Key,
        Cities = new List<string>(g.Select(x => x.City))
      }

      And for $addToSet:

      { $group: {_id: "$State", Cities: { $addToSet: "$City" } } }

      .Group(x => x.State, g => new
      { 
        _id = g.Key,
        Cities = new HashSet<string>(g.Select(x => x.City))
      }

        Attachments

          Activity

            People

            Assignee:
            craiggwilson Craig Wilson
            Reporter:
            craiggwilson Craig Wilson
            Participants:
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved: