Search code examples
c#mongodblookupaggregates

System.FormatException: 'An error occurred while deserializing the property. Using aggregate function with the help of mongoDB.Driver C #


Is there have any way to combine to collections from MongoDB C#

I think the problem with @as...

Created the main class which contains combinations of mail class and profile class. But different error

Created the main class which contains combinations of mail class and profile class. But different error.

In Studio 3T I am getting data

In Studio 3T I am getting data

Models are shown below

Model 1

model 2

model 3

model 4


Solution

  • var Result = await MailCollection.Aggregate()
                .Lookup(
                foreignCollection: ProfileCollection,
                localField: e => e.SenderID,
                foreignField: f => f.Id,
                @as: (MailInfo profile) => profile.SenderInfo
                ).ToListAsync();
    

    SenderInfo property changed to List<Profile>

    enter image description here