0

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

I have tried the following variations of my pipeline

  • var statsPipeline = new[] { new BsonDocument(new BsonElement("$indexStats", BsonNull.Value)) };
  • var statsPipeline = new[] { new BsonDocument { {"$indexStats", "" } } };
  • var statsPipeline = new[] { new BsonDocument { {"$indexStats", null } } };
  • var statsPipeline = new[] { new BsonDocument { {"$indexStats", BsonNull.Value } } };
  • var statsPipeline = new[] { new BsonDocument { {"$indexStats", "{ }"} } };

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?

1
  • I have no experience with MongoDB at all, but try an actual empty (anonymously typed) object: new {}. Commented Jun 20, 2019 at 14:52

1 Answer 1

2

Ok, this one worked:

var statsPipeline = new[] { new BsonDocument(new BsonElement("$indexStats", new BsonDocument())) };
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.