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

Additional $searchMeta test coverage

    • Fully Compatible
    • ALL
    • v6.0
    • Hide

      These can be repro'd locally with mongodb 6.0.0-rc4

      Sharded Collection With Docs On One Shard

      1) Connect to mongos

      2) Setup Collection

      sh.enableSharding("myDb")
      use myDb
      sh.shardCollection("myDb.myCol", {"_id":1}) 
      db.myCol.insertMany([
        {
          "_id": 0,
          "color": "red"
        },
        {
          "_id": 1,
          "color": "blue"
        },
        {
          "_id": 2,
          "color": "green"
        },
        {
          "_id": 3,
          "color": "red"
        },
        {
          "_id": 4,
          "color": "blue"
        },
        {
          "_id": 5,
          "color": "green"
        }
      ])

      3) Define Index on the collection with the given mappings on "myDb.myCol"

      {
          "mappings": {
          "dynamic": false,
          "fields": {
            "color": [
              {
                "type": "stringFacet"
              },
              {
                "type": "string"
              }
            ]
          }
        }
      }

      4) See that this aggregation works, using $search and $project{}

      db.myCol.aggregate([
        {
          "$search": {
              "facet": {
                "operator": {
                  "exists": {
                    "path": "color"
                  }
                },
                "facets": {
                  "colorFacet": {
                    "type": "string",
                    "path": "color",
                  }
                }
              }
            
          }
        },
        {
          "$project": {
            "newField": "$$SEARCH_META"
          }
        }
      ]) 

      5) See that this aggregation fails with the error: Must own one of the two arguments if there are documents in the batch{}

       

      db.myCol.aggregate([
        {
          "$searchMeta": {
              "facet": {
                "operator": {
                  "exists": {
                    "path": "color"
                  }
                },
                "facets": {
                  "colorFacet": {
                    "type": "string",
                    "path": "color",
                  }
                }
              }
            
          }
        }
      ]) 

       

      Unsharded Collection

      1) Connect to mongos

      2) Setup Collection

      sh.enableSharding("myDb")
      use myDb
      db.myColUnsharded.insertMany([
        {
          "_id": 0,
          "color": "red"
        },
        {
          "_id": 1,
          "color": "blue"
        },
        {
          "_id": 2,
          "color": "green"
        },
        {
          "_id": 3,
          "color": "red"
        },
        {
          "_id": 4,
          "color": "blue"
        },
        {
          "_id": 5,
          "color": "green"
        }
      ])

      3) Define Index on the collection with the given mappings on "myDb.myColUnsharded"

      {
          "mappings": {
          "dynamic": false,
          "fields": {
            "color": [
              {
                "type": "stringFacet"
              },
              {
                "type": "string"
              }
            ]
          }
        }
      }

      4) See that this aggregation works, using $search and $project{}

      db.myColUnsharded.aggregate([
        {
          "$search": {
              "facet": {
                "operator": {
                  "exists": {
                    "path": "color"
                  }
                },
                "facets": {
                  "colorFacet": {
                    "type": "string",
                    "path": "color",
                  }
                }
              }
            
          }
        },
        {
          "$project": {
            "newField": "$$SEARCH_META"
          }
        }
      ]) 

      5) See that this aggregation fails and the mongod crashes.{}

      db.myColUnsharded.aggregate([
        {
          "$searchMeta": {
              "facet": {
                "operator": {
                  "exists": {
                    "path": "color"
                  }
                },
                "facets": {
                  "colorFacet": {
                    "type": "string",
                    "path": "color",
                  }
                }
              }
            
          }
        }
      ]) 

       

       

      Show
      These can be repro'd locally with mongodb 6.0.0-rc4 Sharded Collection With Docs On One Shard 1) Connect to mongos 2) Setup Collection sh.enableSharding( "myDb" ) use myDb sh.shardCollection( "myDb.myCol" , { "_id" :1}) db.myCol.insertMany([   {     "_id" : 0,     "color" : "red"   },   {     "_id" : 1,     "color" : "blue"   },   {     "_id" : 2,     "color" : "green"   },   {     "_id" : 3,     "color" : "red"   },   {     "_id" : 4,     "color" : "blue"   },   {     "_id" : 5,     "color" : "green"   } ]) 3) Define Index on the collection with the given mappings on "myDb.myCol" {     "mappings" : {     "dynamic" : false ,     "fields" : {       "color" : [         {           "type" : "stringFacet"         },         {           "type" : "string"         }       ]     }   } } 4) See that this aggregation works, using $search and $project { } db.myCol.aggregate([   {     "$search" : {         "facet" : {           " operator " : {             "exists" : {               "path" : "color"             }           },           "facets" : {             "colorFacet" : {               "type" : "string" ,               "path" : "color" ,             }           }         }            }   },   {     "$project" : {       "newField" : "$$SEARCH_META"     }   } ]) 5) See that this aggregation fails with the error: Must own one of the two arguments if there are documents in the batch { }   db.myCol.aggregate([   {     "$searchMeta" : {         "facet" : {           " operator " : {             "exists" : {               "path" : "color"             }           },           "facets" : {             "colorFacet" : {               "type" : "string" ,               "path" : "color" ,             }           }         }            }   } ])   Unsharded Collection 1) Connect to mongos 2) Setup Collection sh.enableSharding( "myDb" ) use myDb db.myColUnsharded.insertMany([   {     "_id" : 0,     "color" : "red"   },   {     "_id" : 1,     "color" : "blue"   },   {     "_id" : 2,     "color" : "green"   },   {     "_id" : 3,     "color" : "red"   },   {     "_id" : 4,     "color" : "blue"   },   {     "_id" : 5,     "color" : "green"   } ]) 3) Define Index on the collection with the given mappings on "myDb.myColUnsharded" {     "mappings" : {     "dynamic" : false ,     "fields" : {       "color" : [         {           "type" : "stringFacet"         },         {           "type" : "string"         }       ]     }   } } 4) See that this aggregation works, using $search and $project { } db.myColUnsharded.aggregate([   {     "$search" : {         "facet" : {           " operator " : {             "exists" : {               "path" : "color"             }           },           "facets" : {             "colorFacet" : {               "type" : "string" ,               "path" : "color" ,             }           }         }            }   },   {     "$project" : {       "newField" : "$$SEARCH_META"     }   } ]) 5) See that this aggregation fails and the mongod crashes. { } db.myColUnsharded.aggregate([   {     "$searchMeta" : {         "facet" : {           " operator " : {             "exists" : {               "path" : "color"             }           },           "facets" : {             "colorFacet" : {               "type" : "string" ,               "path" : "color" ,             }           }         }            }   } ])    
    • QO 2022-05-16, QO 2022-05-30, QO 2022-06-13, QO 2022-06-27, QO 2022-07-11, QO 2022-07-25, QO 2022-08-08

      When testing with 6.0.0-rc4 in cloud-dev, I ran into a few issues with $searchMeta when run against an unsharded collection & against a sharded collection with all of its docs on a single shard.

      When I run a $searchMeta query against a sharded collection, where docs are only present on a single shard, I receive this error:

       

      {"t":{"$date":"2022-05-09T23:20:06.685+00:00"},"s":"I""c":"QUERY",    "id":4625501, "ctx":"conn27","msg":"Unable to establish remote cursors","attr":{"error":{"code":6253102,"codeName":"Location6253102","errmsg":"Must own one of the two arguments if there are documents in the batch"},"nRemotes":0}} 

      When I run a $searchMeta query against a totally unsharded collection, the mongod running the query crashes.  I have attached this log of the mongod that crashed: unsharded_logs.txt(Within this log, I also ran the same $search query and accessed $$SEARCH_META successfully through $project)

       

      In both scenarios, when I use a normal $search query with $project to access $$SEARCH_META, it works correctly.

      I've also attached local repros.  Cloud-dev is seeing issues with the mongotHost parameter so can't repro there yet.

        1. unsharded_logs.txt
          1.33 MB
          Evan Plotkin

            Assignee:
            charlie.swanson@mongodb.com Charlie Swanson
            Reporter:
            evan.plotkin@mongodb.com Evan Plotkin
            Votes:
            0 Vote for this issue
            Watchers:
            7 Start watching this issue

              Created:
              Updated:
              Resolved: