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

Document is not found when searching on a field indexed by a hash index using a $in clause with regular expression

    • Fully Compatible
    • ALL
    • Hide
      db.genes.insert({   "_id": "gn22",   "D": 3,   "C": "chr1",   "O": "ENSEMBL",   "T": "gene",   "S": 200880,   "E": 201017,   "R": 1.1754943508222875e-38,   "N": 43,   "M": 46,   "I": {     "gene_id": "ENSG00000275135.1",     "gene_type": "miRNA",     "gene_status": "NOVEL",     "gene_name": "FO538757.1",     "level": "3"   } })
      Inserted 1 record(s) in 160ms
      WriteResult({
        "nInserted": 1
      })
      
      db.genes.find({gene})
      
      // Simple search with regular expression: OKAY
      db.genes.find({"I.gene_name": /FO538757/i})
      {
        "_id": "gn22",
        "D": 3,
        "C": "chr1",
        "O": "ENSEMBL",
        "T": "gene",
        "S": 200880,
        "E": 201017,
        "R": 1.1754943508222875e-38,
        "N": 43,
        "M": 46,
        "I": {
          "gene_id": "ENSG00000275135.1",
          "gene_type": "miRNA",
          "gene_status": "NOVEL",
          "gene_name": "FO538757.1",
          "level": "3"
        }
      }
      
      // Search with $in and regular expression without index: OKAY
      db.genes.find({"I.gene_name": {$in: [/FO538757/i]}})
      {
        "_id": "gn22",
        "D": 3,
        "C": "chr1",
        "O": "ENSEMBL",
        "T": "gene",
        "S": 200880,
        "E": 201017,
        "R": 1.1754943508222875e-38,
        "N": 43,
        "M": 46,
        "I": {
          "gene_id": "ENSG00000275135.1",
          "gene_type": "miRNA",
          "gene_status": "NOVEL",
          "gene_name": "FO538757.1",
          "level": "3"
        }
      }
      
      // Create index: OKAY
      db.genes.ensureIndex({"I.gene_name":"hashed"})
      {
        "createdCollectionAutomatically": false,
        "numIndexesBefore": 1,
        "numIndexesAfter": 2,
        "ok": 1
      }
      
      // Search on a simple search and HASHED INDEX: OKAY
      db.genes.find({"I.gene_name": /FO538757/i})
      {
        "_id": "gn22",
        "D": 3,
        "C": "chr1",
        "O": "ENSEMBL",
        "T": "gene",
        "S": 200880,
        "E": 201017,
        "R": 1.1754943508222875e-38,
        "N": 43,
        "M": 46,
        "I": {
          "gene_id": "ENSG00000275135.1",
          "gene_type": "miRNA",
          "gene_status": "NOVEL",
          "gene_name": "FO538757.1",
          "level": "3"
        }
      }
      
      // Search with $in and regular expression AND HeASHED INDEX: Not found :-(
      db.genes.find({"I.gene_name": {$in: [/FO538757/i]}})
      Fetched 0 record(s) in 1ms
      
      // Dropping the index
      db.genes.dropIndex({"I.gene_name": "hashed"})
      {
        "nIndexesWas": 2,
        "ok": 1
      }
      
      // Search with $in and regular expression after dropped the index: Okay
      db.genes.find({"I.gene_name": {$in: [/FO538757/i]}})
      {
        "_id": "gn22",
        "D": 3,
        "C": "chr1",
        "O": "ENSEMBL",
        "T": "gene",
        "S": 200880,
        "E": 201017,
        "R": 1.1754943508222875e-38,
        "N": 43,	
        "M": 46,
        "I": {
          "gene_id": "ENSG00000275135.1",
          "gene_type": "miRNA",
          "gene_status": "NOVEL",
          "gene_name": "FO538757.1",
          "level": "3"
        }
      }
      
      Show
      db.genes.insert({ "_id": "gn22", "D": 3, "C": "chr1", "O": "ENSEMBL", "T": "gene", "S": 200880, "E": 201017, "R": 1.1754943508222875e-38, "N": 43, "M": 46, "I": { "gene_id": "ENSG00000275135.1", "gene_type": "miRNA", "gene_status": "NOVEL", "gene_name": "FO538757.1", "level": "3" } }) Inserted 1 record(s) in 160ms WriteResult({ "nInserted": 1 }) db.genes.find({gene}) // Simple search with regular expression: OKAY db.genes.find({"I.gene_name": /FO538757/i}) { "_id": "gn22", "D": 3, "C": "chr1", "O": "ENSEMBL", "T": "gene", "S": 200880, "E": 201017, "R": 1.1754943508222875e-38, "N": 43, "M": 46, "I": { "gene_id": "ENSG00000275135.1", "gene_type": "miRNA", "gene_status": "NOVEL", "gene_name": "FO538757.1", "level": "3" } } // Search with $in and regular expression without index: OKAY db.genes.find({"I.gene_name": {$in: [/FO538757/i]}}) { "_id": "gn22", "D": 3, "C": "chr1", "O": "ENSEMBL", "T": "gene", "S": 200880, "E": 201017, "R": 1.1754943508222875e-38, "N": 43, "M": 46, "I": { "gene_id": "ENSG00000275135.1", "gene_type": "miRNA", "gene_status": "NOVEL", "gene_name": "FO538757.1", "level": "3" } } // Create index: OKAY db.genes.ensureIndex({"I.gene_name":"hashed"}) { "createdCollectionAutomatically": false, "numIndexesBefore": 1, "numIndexesAfter": 2, "ok": 1 } // Search on a simple search and HASHED INDEX: OKAY db.genes.find({"I.gene_name": /FO538757/i}) { "_id": "gn22", "D": 3, "C": "chr1", "O": "ENSEMBL", "T": "gene", "S": 200880, "E": 201017, "R": 1.1754943508222875e-38, "N": 43, "M": 46, "I": { "gene_id": "ENSG00000275135.1", "gene_type": "miRNA", "gene_status": "NOVEL", "gene_name": "FO538757.1", "level": "3" } } // Search with $in and regular expression AND HeASHED INDEX: Not found :-( db.genes.find({"I.gene_name": {$in: [/FO538757/i]}}) Fetched 0 record(s) in 1ms // Dropping the index db.genes.dropIndex({"I.gene_name": "hashed"}) { "nIndexesWas": 2, "ok": 1 } // Search with $in and regular expression after dropped the index: Okay db.genes.find({"I.gene_name": {$in: [/FO538757/i]}}) { "_id": "gn22", "D": 3, "C": "chr1", "O": "ENSEMBL", "T": "gene", "S": 200880, "E": 201017, "R": 1.1754943508222875e-38, "N": 43, "M": 46, "I": { "gene_id": "ENSG00000275135.1", "gene_type": "miRNA", "gene_status": "NOVEL", "gene_name": "FO538757.1", "level": "3" } }
    • Quint 9 09/18/15

      I have a collection, where I index one of the fields with the hash index.
      No results are found when I perform a search on this field using $in with regular expression.

      -
      Extras:
      If I used the "normal" index, the command finds the document.
      I only tested with the out of the box configurations: Get mongodb, uncompress, execute mongod, open mongo shell.

            Assignee:
            dan@mongodb.com Daniel Pasette (Inactive)
            Reporter:
            felipe.albrecht Felipe Albrecht
            Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

              Created:
              Updated:
              Resolved: