public async Task <IEnumerable <AuditoriumDetailedInfo> > GetDetailedInfoAsync() { var result = await Housings .Aggregate() .Unwind(field => field.Auditoriums) .Project(new BsonDocument { { "Id", "$Auditoriums.Id" }, { "Number", "$Auditoriums.Number" }, { "Capacity", "$Auditoriums.Capacity" }, { "HousingNumber", "$Number" }, { "Floor", "$Auditoriums.Floor" }, { "Type", "$Auditoriums.Type" } }) .ToListAsync(); return(result.Select(r => BsonSerializer.Deserialize <AuditoriumDetailedInfo>(r)).ToList()); }
public async Task <IEnumerable <HousingDetailedInfo> > GetDetailedInfoAsync() { var result = await Housings .Aggregate() .Unwind(h => h.Auditoriums) .Group(new BsonDocument { { "_id", new BsonDocument { { "number", "$Number" }, { "type", "$Auditoriums.Type" } } }, { "CapacityCount", new BsonDocument { { "$sum", "$Auditoriums.Capacity" } } }, { "Count", new BsonDocument { { "$sum", 1 } } } }) .Group(new BsonDocument { { "_id", new BsonDocument { { "number", "$_id.number" } } }, { "TotalCapacity", new BsonDocument { { "$sum", "$CapacityCount" } } }, { "CountPerType", new BsonDocument { { "$push", new BsonDocument { { "type", "$_id.type" }, { "count", "$Count" } } } } } }) .Project(new BsonDocument { { "Number", "$Number" }, { "CountPerType", "$CountPerType" }, { "TotalCapacity", "$TotalCapacity" } }) .ToListAsync(); return(result.Select(r => r.AsHousingDetailedInfo()).ToList()); }