Uploaded image for project: 'Documentation'
  1. Documentation
  2. DOCS-15298

[Server] Investigate changes in SERVER-65808: $search as subpipeline of $lookup with localField+foreignField is not supported

      Original Downstream Change Summary

      This change allows usage of localField/foreignField in $lookup pipeline with $search

      Description of Linked Ticket

      A pipeline like this works as expected:

      [{
        "$lookup": {
          "from": "suppliers",
          "let": { "s": "address.state" },
          "as": "details",
          "pipeline": [
            {
              "$search": {
                "text": {
                  "query": "green",
                  "path": "description"
                }
              }
            },
            { "$match": { "$expr": { "$eq": ["$$s", "$address.state"] } } }
          ]
        }
      }
      ] 

      But equivalent expressed with localField/foreignField produces an error.

       
      db.test.aggregate([{ 
        "$lookup": { 
          "from": "suppliers", 
          "localField": "address.state", 
          "foreignField": "address.state", 
          "as": "details", 
          "pipeline": [ 
            { 
              "$search": { 
                "text": { 
                  "query": "green", 
                  "path": "description" 
                } 
              } 
            } 
          ] 
        } 
      }]) 
      

      "$_internalSearchMongotRemote is only valid as the first stage in a pipeline"

      Scope of Changes

      Spoke with kanchana.sekhar@mongodb.com on this. What we want to do on the server docs side is:

      • Mention this change in the release notes
      • Add a sub-section to the Examples section of $lookup called "$search Examples" and link out to the new tutorials being created in the Atlas Search docs.

      Timing

      Not required for World. The tutorials will be written post World.

            Assignee:
            kanchana.sekhar@mongodb.com Kanchana Sekhar
            Reporter:
            backlog-server-pm Backlog - Core Eng Program Management Team
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved:
              2 years ago