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

$search as subpipeline of $lookup with localField+foreignField is not supported

    • Type: Icon: Improvement Improvement
    • Resolution: Fixed
    • Priority: Icon: Major - P3 Major - P3
    • 6.0.0-rc4, 6.1.0-rc0
    • Affects Version/s: 6.0.0-rc0
    • Component/s: Querying
    • Minor Change
    • v6.0
    • QO 2022-05-02

      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"

            Assignee:
            ruslan.abdulkhalikov@mongodb.com Ruslan Abdulkhalikov (Inactive)
            Reporter:
            kateryna.kamenieva@mongodb.com Katya Kamenieva
            Votes:
            0 Vote for this issue
            Watchers:
            7 Start watching this issue

              Created:
              Updated:
              Resolved: