M220N User Report Ticket

Trying to figure out this User Report ticket. here is my current code:

     var filter = Builders<BsonDocument>.Projection

                result = await _commentsCollection
                    .Group(new BsonDocument
                            { "id", "$email" },
                            new BsonDocument ("$sum", 1)}
                    .Sort(new BsonDocument("count", -1))

I think I need to use a Bson document instead of a builder for the projection, but am not sure how to do that. Any guidance welcome!

I think you want to sort based on the number of comments rather than the email.

1 Like

Thanks. I have adjusted that but am still getting the following error:

Argument 1: cannot convert from ‘MongoDB.Driver.ProjectionDefinition<M220N.Models.Projections.ReportProjection>’ to ‘MongoDB.Driver.ProjectionDefinition<MongoDB.Bson.BsonDocument, M220N.Models.Projections.ReportProjection>’ [/Users/shelby/Downloads/mflix-cs/M220N/M220N.csproj]

This is too specific to .Net for me to help. I do not know .Net and I am not planning to learn.

May be id within Group needs to be _id instead. But that won’t fix the error.

gotcha. thanks anyway!

Figured it out. I needed to use in my builder for the projection instead of .