2

I am trying to perform a join on a collection from the results of a select many using the MongoDb Linq driver

pseudo code is

from x in something
from y in x.subcollection
join a in detailed on y.id equals a.id
select new 
{
   x.field,
   x.someotherfield,
   a.somedetail,
   a.someotherdetail
}

unfortunately this syntax gives me

System.NotSupportedException : $project or $group does not support {document}.

I would be open to doing this via the aggregate pipeline fluent library as well, if its not possible using the linq provider, but I have no idea of the syntax, the documentation is ... lacking ...

I assume it would be an unwind, a lookup and a projection - but how?

-------Edit-------

Getting closer, but still no cigar...

enter image description here

So the unwind seems to work fine, the lookup also works fine, the issue is trying to work with the resulting BsonDocument in the projection stage

I know that there are some typed overloads where I could supply a type - but it will be impractical to create intermediate types for every stage of every pipeline.

My issues are.

  • I seem to have to hard cast the BsonValue's rather than use the AsSomething methods, which seems weird (bug?)
  • The joined collection is included as an Array (as expected) in my case it will always have 1 record, I can get the First ok as a BSonDocument, but I cannot drill further into it (the ["FirstName"] call fails with "No matching creator found"

Please help !

Tim Jarvis
  • 18,465
  • 9
  • 55
  • 92
  • 1
    I looked here: https://www.axonize.com/blog/joining-collections-mongodb-using-c-driver-linq/ – tdayi Oct 17 '18 at 07:50

0 Answers0