I have a mongoDB collection containing items that can be identified through multiple identification schemes
{
"identification" : {
"SCHEME1" : [ "9181983" ],
"SCHEME2" : [ "ABC" , "CDE" ],
"SCHEME4" : ["FDE"]
}
}
{
"identification" : {
"SCHEME2" : [ "LALALAL" ],
"SCHEME5" : [ "CH98790789879" ]
}
},
An item will most likely have not all identification schemes, some have (like the example above ) 1-2-4 others may have different ones. The number of identification schemes is not finally defined and will grow. Every identification can only exists once.
I want to perform two different queries:
Seach an item with scheme and identification, e.g.
db.item.find({"identification.SCHEME2": "CDE"})
Seach all items with a specific identification scheme, e.g.
db.item.find({"identification.SCHEME2": {$exists: true}})
My approach was to create sparse indexes:
db.item.createIndex( { identification.SCHEME1: 1 }, { sparse: true, unique: true} );
db.item.createIndex( { identification.SCHEME2: 1 }, { sparse: true, unique: true } );
db.item.createIndex( { identification.SCHEME3: 1 }, { sparse: true, unique: true } );
and so on ....
This approach worked perfectly until I found out that there is a limit of 64 indexes on one collection in mongoDB.
Has anyone an idea how I could index the whole field "identification" with one index ? Or is my document structure wrong ? Any ideas are welcome, thanks.