0

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

GSH
  • 239
  • 1
  • 5
  • 16

1 Answers1

1

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"})
rrrr-o
  • 2,447
  • 2
  • 24
  • 52
  • I only have one method Aggregate(BsonDocument). I don't see Aggragate().Group(BsonDocument) – GSH Aug 15 '17 at 07:42
  • @GSH It's definitely there, we are using it and it's in the docs https://docs.mongodb.com/getting-started/csharp/aggregation/. As I said all you seemed to be missing was the ToList() call and it worked fine for me. Hard to comment any further without seeing more code. – rrrr-o Aug 15 '17 at 08:01
  • I was missing MongoDB.Driver.Linq namespace. – GSH Aug 17 '17 at 12:28