We are currently managing a set of permissions as a Map on a collection. Each set of permissions is filed with the user's id as key. For some reason that key is currently a stringified version of a BSONObjectID.
I would like to maintain an index on the key, so I can lookup the relevant set of permissions only, and also find those documents where permissions for specific user is present.
edit: example added:
Example:
{"_id" : {"$oid" : "xxxxxx"},
"irrelevantData" : "Document1 data...",
"permissions" : {
"key1" : {"perm1" : true, "perm2: false},
"key3" : {"perm1" : true, "perm2: false}
}
{"_id" : {"$oid" : "yyyyyy"},
"irrelevantData" : "Document2 data...",
"permissions" : {
"key1" : {"perm1" : false, "perm2: true},
"key2" : {"perm1" : true, "perm2: false}
}
In the example above, I'd like my index to be able to pick only documents where "key2" is present in permissions.
The model is like this:
case class relevantCollection(
_id: BSONObjectID,
irrelevantData: String,
permissions: Option[Map[String, Map[String, Boolean]]]
)
How do I create an index on a key instead of a value? Is there any performance issue, regarding this key being a String vs. a BSONObjectID?