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

Return single object instead of array in $lookup if useer want

    • Type: Icon: New Feature New Feature
    • Resolution: Duplicate
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: None
    • Component/s: Aggregation Framework
    • None
    • Query

      When we use $lookup in aggregate query of MongoDB we use this format

      {
         $lookup:
           {
             from: "users",
             localField: "userId",
             foreignField: "_id",
             as: "user"
           }
      }
      

      where user return as an array of object and then some time we need to use $arrayElemAt in $project stage to return as a single object. like

      {
        $project:
         {
          user:
            { 
              $arrayElemAt: [ "$user", 0 ] 
            }
         }
      }
      

      so my request is can create option to return user as a single object instead of array from $lookup stage ?

            Assignee:
            backlog-server-query Backlog - Query Team (Inactive)
            Reporter:
            shaishab Shaishab Roy
            Votes:
            1 Vote for this issue
            Watchers:
            7 Start watching this issue

              Created:
              Updated:
              Resolved: