1

I'm trying to write a very simple grouping query, using the MongoDB fluent aggregation syntax in the C# driver.

I'm grouping documents by author and returning the count per author. I don't need to return the author names, only the counts. The following code compiles, but when I execute it, I get this exception:

Command aggregate failed: the group aggregate field name '$sum' cannot be an operator name.

var query = Collection<TestFile>()
    .Aggregate()
    .Group(
        t => t.AuthorName,
        grp => grp.Count()
     )
     .ToEnumerable();

MongoDB version: 3.2.4

MongoDB C# Driver version: 2.2.3.3

1 Answer 1

1

Try it like so (not tested yet though)

var query = Collection<TestFile>()
    .Aggregate()
    .Group(
        t => t.AuthorName,
        grp => new { Count = grp.Count() }
     )
     .ToEnumerable();
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.