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

$search with access to $$SEARCH_META followed by $lookup returns no results in 7.3.0-rc1

    • Type: Icon: Bug Bug
    • Resolution: Duplicate
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: None
    • Component/s: None
    • ALL
    • Hide

      Populate db/coll:

       

      db.search1.insertMany([{name: "apple jam"},{name:"strawberry jam"},{name: "apple blueberry jam"}])
      db.search2.insertMany([{name: "blueberry jam"},{name:"strawberry jam"}])
      

       

      Query:

       

      db.search1.aggregate([{$search: {text:{path: "name", query: "apple"}}}, {$addFields: {score: {$meta: "searchScore"}, searchMeta: "$$SEARCH_META"}}, {$lookup: {from: "search2", localField: "name", foreignField: "name", as: "match"}}]) 
      [
      {     _id: ObjectId("65c169267ad0e23fd198464b"),     name: 'apple jam',     score:
      { meta: 'searchScore' }
      ,
          searchMeta: { count:
      { lowerBound: Long("2") }
      },
          match: []
        },
       
      {     _id: ObjectId("65c169267ad0e23fd198464d"),     name: 'apple blueberry jam',     score:
      { meta: 'searchScore' }
      ,
          searchMeta: { count:
      { lowerBound: Long("2") }
      },
          match: []
        }
      ]
      
      
      

       

      Even if the results from $lookup stored in the "match" field are empty, I still expect to see 2 documents returned as shown, but instead I'm seeing zero documents returned.

      Show
      Populate db/coll:   db.search1.insertMany([{name: "apple jam" },{name: "strawberry jam" },{name: "apple blueberry jam" }]) db.search2.insertMany([{name: "blueberry jam" },{name: "strawberry jam" }])   Query:   db.search1.aggregate([{$search: {text:{path: "name" , query: "apple" }}}, {$addFields: {score: {$meta: "searchScore" }, searchMeta: "$$SEARCH_META" }}, {$lookup: {from: "search2" , localField: "name" , foreignField: "name" , as: "match" }}])  [ {     _id: ObjectId( "65c169267ad0e23fd198464b" ),     name: 'apple jam' ,     score: { meta: 'searchScore' } ,     searchMeta: { count: { lowerBound: Long ( "2" ) } },     match: []   },   {     _id: ObjectId( "65c169267ad0e23fd198464d" ),     name: 'apple blueberry jam' ,     score: { meta: 'searchScore' } ,     searchMeta: { count: { lowerBound: Long ( "2" ) } },     match: []   } ]   Even if the results from $lookup stored in the "match" field are empty, I still expect to see 2 documents returned as shown, but instead I'm seeing zero documents returned.

      Using 7.3.0-rc1 caused an existing test to fail in ADFA that may indicate a bug with $$SEARCH_META used with $lookup.

      I'm seeing no documents returned when querying using $search and accessing the $$SEARCH_META variable followed by a $lookup. The $search query itself should end up returning 3 documents, but when followed by a $lookup stage returns 0. I don't think this is expected behavior.

      See steps to reproduce for a similar example.

            Assignee:
            charlie.swanson@mongodb.com Charlie Swanson
            Reporter:
            ann.wang@mongodb.com Ann Wang
            Votes:
            0 Vote for this issue
            Watchers:
            11 Start watching this issue

              Created:
              Updated:
              Resolved: