Aggregate with Sort - Mongodb

Asked

Viewed 106 times

1

I have a query in Mongodb, I do Aggregate to count how many items there are in each category, everything works well, however I can’t sort the data, that would be ordered by the Title field. Follow the code, in which I’ve made numerous changes:

var aggregate = collection.Aggregate()
            .Match(filters)
            .Group(new BsonDocument { { "_id", "$CategoryId" }, { "count", new BsonDocument("$sum", 1) } })
            .Sort(new BsonDocument("Title", 1));
            //.Project(new BsonDocument { { "Title", 1 }, { "count", 1 } });
  • Already tried to put Sort after Group?

  • yes, it’s changed several times, I ended up posting like this, I’ll even change.

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.