$ facet没有反序列化

时间:2018-12-24 13:44:37

标签: c# mongodb mongodb-.net-driver

我正在尝试运行此命令:

var applicationsPipeline = PipelineDefinition<AffiliateRecord, List<ApplicationRecord>>.Create(new IPipelineStageDefinition[] {
    PipelineStageDefinitionBuilder.Match<AffiliateRecord>(filter),
    PipelineStageDefinitionBuilder.Unwind<AffiliateRecord, AffiliateRecord>("Applications"),
    PipelineStageDefinitionBuilder.Match<AffiliateRecord>(matchApplications),
    PipelineStageDefinitionBuilder.ReplaceRoot<AffiliateRecord, List<ApplicationRecord>>(x => x.Applications),
    PipelineStageDefinitionBuilder.Skip<List<ApplicationRecord>>(offset),
    PipelineStageDefinitionBuilder.Limit<List<ApplicationRecord>>(limit),
});

var applicationsFacet = AggregateFacet.Create("applications", applicationsPipeline);

var aggregate = collection
    .Aggregate()
    .Facet(applicationsFacet, ...);

var facetResult = await aggregate.SingleOrDefaultAsync();

但我遇到此错误:

System.FormatException: Cannot deserialize a 'List<ApplicationRecord>' from BsonType 'Document'.

我想念什么?

1 个答案:

答案 0 :(得分:0)

我能够使它像这样工作:

var applicationsPipeline = PipelineDefinition<AffiliateRecord, ApplicationRecord>.Create(new IPipelineStageDefinition[] {
       PipelineStageDefinitionBuilder.Match<AffiliateRecord>(filter),
       PipelineStageDefinitionBuilder.Unwind<AffiliateRecord>(x => x.Applications),
       PipelineStageDefinitionBuilder.Match<BsonDocument>(new BsonDocument("$and", and)),
       PipelineStageDefinitionBuilder.ReplaceRoot<BsonDocument, ApplicationRecord>("$Applications"),
       PipelineStageDefinitionBuilder.Skip<ApplicationRecord>(offset),
       PipelineStageDefinitionBuilder.Limit<ApplicationRecord>(limit)
 });

这使我认为ReplaceRoot有某种错误,因为它迫使我将Toutput设置为List而不是ApplicationRecord。