GSH
GSH

Reputation: 249

Aggregation with Mongodb c# Driver 2.4 not working

When using the commands as below, it returning null.

        var pipeline = new BsonDocument[] {
            new BsonDocument{{"$group", new BsonDocument{{"_id", "$BrandId"}}}}
        };

        var brands = context
            .Items.Aggregate<BsonDocument>(pipeline);

enter image description here

Data ex:

enter image description here

The Aggregation method I have as shown below:

enter image description here

Upvotes: 0

Views: 415

Answers (1)

rrrr-o
rrrr-o

Reputation: 2516

It seems that all you are missing is doing a ToList() or ToListAsync() after the Aggregate() call to make it return the data.

Is there a reason you are not using the Group method instead?

Aggregate().Group(new BsonDocument() { "_id" : "$BrandId"})

Upvotes: 1

Related Questions