Uploaded image for project: 'Core Server'
  1. Core Server
  2. SERVER-85612

$lookup on array field matches documents without the foreignField

    • Type: Icon: Bug Bug
    • Resolution: Unresolved
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: None
    • Component/s: None
    • Labels:
      None

      I've created a MongoDB playground the illustrates the issue: https://mongoplayground.net/p/ZBs-X9VnNsX.

       

      If this is not a bug, it's certainly not the behavior I expected. It appears that when I do two sequential lookups, where the second lookup uses an ID from the document produced by the first lookup, if the any documents in the second lookup's collection are missing the foreignField, then they will be returned in the $lookup.

       

      I suspect that the cause is because if the $lookup.fromField is an array, and that array is empty, we match $foriegnField on `null`. Is this actually preferred behavior?

            Assignee:
            kateryna.kamenieva@mongodb.com Katya Kamenieva
            Reporter:
            clark.mccauley@printtrackerpro.com Clark McCauley
            Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

              Created:
              Updated: