Kit
Kit

Reputation: 21719

How do I represent an "empty object" for MongoDB .NET Driver?

I am trying to retrieve index statistics using the MongoDB .NET Driver.

I have tried the following variations of my pipeline

which is passed to the query

var stats = await db
    .GetCollection<BsonDocument>("CollectionName")
    .AggregateAsync<BsonDocument>(statsPipeline);

With the exception of the one containing null, which resulted in an ArgumentNullException, I have received the exception

MongoDB.Driver.MongoCommandException: Command aggregate failed: The $indexStats stage specification must be an empty object.

How do I change my query such that the $indexStats stage specification is indeed an empty object?

Upvotes: 0

Views: 919

Answers (1)

Kit
Kit

Reputation: 21719

Ok, this one worked:

var statsPipeline = new[] { new BsonDocument(new BsonElement("$indexStats", new BsonDocument())) };

Upvotes: 2

Related Questions