【发布时间】:2019-06-20 14:42:12
【问题描述】:
我正在尝试使用 MongoDB .NET 驱动程序检索索引统计信息。
我已经尝试过我的管道的以下变体
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", "{ }"} } };
传递给查询
var stats = await db
.GetCollection<BsonDocument>("CollectionName")
.AggregateAsync<BsonDocument>(statsPipeline);
除了包含null 的那个导致ArgumentNullException 之外,我收到了异常
MongoDB.Driver.MongoCommandException:命令聚合失败:$indexStats 阶段规范必须是空对象。
如何更改我的查询以使 $indexStats 阶段规范确实是一个空对象?
【问题讨论】:
-
我完全没有使用 MongoDB 的经验,但尝试一个实际的空(匿名输入)对象:
new {}。