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"
}
}