如何为 MongoDB .NET 驱动程序表示 "empty object"?
How do I represent an "empty object" for MongoDB .NET Driver?
我正在尝试使用 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: Command aggregate failed: The $indexStats stage specification must be an empty object.
如何更改我的查询,使 $indexStats
阶段规范确实是一个空对象?
好的,这个有效:
var statsPipeline = new[] { new BsonDocument(new BsonElement("$indexStats", new BsonDocument())) };
我正在尝试使用 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: Command aggregate failed: The $indexStats stage specification must be an empty object.
如何更改我的查询,使 $indexStats
阶段规范确实是一个空对象?
好的,这个有效:
var statsPipeline = new[] { new BsonDocument(new BsonElement("$indexStats", new BsonDocument())) };