-
Type: Bug
-
Resolution: Unresolved
-
Priority: Major - P3
-
None
-
Affects Version/s: 2.9.2
-
Component/s: Builders
-
None
-
Environment:Ubuntu 18.04 LTS
Hi Team,
i have to order a collection by a date attribute from a foreign collection. I'm trying to do this:
await _context.MainCollection
.Aggregate()
.Match(mc => someIds.Contains(mc.Id)) //Only some registers
.Lookup<MainEntity, ForeignEntity, MainEntityWithForeign>(
_context.ForeignCollection,
mc => mc.Id,
fc => fc.MainCollectionId,
mewf => mewf.ForeignCollections
)
.SortByDescending(x => x.ForeignCollections.First().CreationDate)
but this does not work and my results are not ordered. The query generated considers my order attribute as part of the main collection instead of the foreign collection:
{ "$sort" : \{ "creationDate" : -1 } }
When I replace the method "First()" for "ElementAt(0)" its works as expected, and the generated query order command is the one below:
{ "$sort" : \{ "foreignCollections.0.creationDate" : -1 } }
I think there is a bug when the driver tries to translate to the Mongo query when I use the method "First()".
Thank you.