Add count to this lookup

how can I add count to this query:
new BsonDocument
new BsonDocument("lookup", new BsonDocument { { "from", "comments" }, { "let", new BsonDocument("id", "_id") },
{ “pipeline”,
new BsonArray
new BsonDocument("$match",
new BsonDocument("$expr",
new BsonDocument("$eq",
new BsonArray
new BsonDocument("$sort", new BsonDocument(“time”, -1)),
new BsonDocument("$limit", Filters.defaultCommentsLimitPerPost),
{ “as”, “comments” }
new BsonDocument("$limit", 6),
new BsonDocument("$skip", page - 1),

When I try to add $count, I get the count but I don’t get any of the documents.

Hi @Rony_Tesler,

Why do you need a count?


I want to implement paging and I want the client to know the total number of records.
This BsonDocument way of coding is so inconvenient, it’s not clear when to use a new BsonDocument, when to use {} etc., and it’s too difficult to convert code examples found on the internet. Is there a more comprehensive course that explains all the ways of using the C# driver?

1 Like

Any update?
I’m tryihng to use a $facet but it’s too complicated using all these BsonDocument objects.