G
G
Geronom2020-11-04 15:35:34
MongoDB
Geronom, 2020-11-04 15:35:34

C# MongoDb driver Aggregate from different collections?

There are 4 collections, which are described by the following models:

class A
{
    public ObjectId a_id { get; set; }
    public List<B> fields { get; set; }
}

class B
{
    public ObjectId b_id { get; set; }
    public string b_item { get; set; }
}

class C
{
    public ObjectId c_id { get; set; }
    public ObjectId b_id { get; set; }
    public ObjectId d_id { get; set; }
    public string c_item { get; set; }
}

class D
{
    public ObjectId d_id { get; set; }
    public string d_item { get; set; }
}


Only a_id is set in order to get a list of fields from class A.

How to get the Result class by aggregation, which will contain the following data:

class Result
{
    public string item { get; set; } // item = b_item
    public List<ResultItem> items { get; set; }
}

class ResultItem
{
    public string str { get; set; } // str = d_item
    public string item { get; set; } // item = c_item
}

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question