Unwind then Group aggregation in MongoDB C#
When you let Unwind
infer the type parameters it will use the collection type for TResult
and BsonDocument
for TNewResult
.
If you want to use a specific type and not BsonDocument
you need to add these type parameters:
var pipeline = usersCollection.Aggregate() .Unwind<OriginalType, NewResultType>(....
As always, you need to make sure the operation actually returns something that can be of that type.