Querying objects in sub-array and returning each as an individual overall document in C# using MongoDB Driver

Hi all,

I’m currently looking into trying to figure out how to use a C# API to query my MongoDB collection that stores multiple embedded objects within each record.

For example, my data looks something like this:

Main Object:

_id: ObjectId(...)
serialNumber: "A"
points: Array 

Under the points object, suppose there are 10 points such that

0: Object
Time: "2022-01-20T00:00:00:000"

1: Object
Time: "2022-01-20T00:02:00:000"

and so forth

How, if possible, would I be able to return the data in a list format such that it returns 10 separate records from this one record, in a format such as:

serialNumber: "A"
Time: "2022-01-20T00:00:00:000"

serialNumber: "A"
Time: "2022-01-20T00:02:00:000"

Currently, I’m using a filter and a projection using just the main object, and when I try to include the embedded object, I get a response that looks like this:

fieldBuilder.Include(x => x.serialNumber).Include("Points.Time") but that returns in the 


serialNumber: "A"
points: [
     {Time: "2022-01-20T00:00:00:000"}
     {Time: "2022-01-20T00:02:00:000"}

Is there any way to build a filter or projection, using two separate objects, to aggregate these values together and return a list of 10 records in a GET request?

The current solution I’m using involves a nested foreach loop that basically loops through the entire document and adds each embedded point to the projection of the main object and returns the 10 in proper list format, but that seems quite inefficient.

Any help is appreciated :slight_smile: