Unable to use "First()" when sort by a property from a lookup foreign document

XMLWordPrintableJSON

    • Type: Bug
    • Resolution: Gone away
    • Priority: Major - P3
    • None
    • Affects Version/s: 2.9.2
    • Component/s: Builders
    • None
    • Environment:
      Ubuntu 18.04 LTS
    • None
    • Hide

      1. What would you like to communicate to the user about this feature?
      2. Would you like the user to see examples of the syntax and/or executable code and its output?
      3. Which versions of the driver/connector does this apply to?

      Show
      1. What would you like to communicate to the user about this feature? 2. Would you like the user to see examples of the syntax and/or executable code and its output? 3. Which versions of the driver/connector does this apply to?
    • None
    • None
    • None
    • None
    • None
    • None

      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.

            Assignee:
            Unassigned
            Reporter:
            Luiz Guilherme Rodrigues
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: