How to create a MongoDb index on key-name in Map[key, value]?
<p>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.</p>

<p>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.</p>

<p><em>edit: example added:</em><br>
Example: </p>

<pre><code>{"_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}  
}
</code></pre>

<p>In the example above, I'd like my index to be able to pick only documents where "key2" is present in permissions.</p>

<p>The model is like this:</p>

<pre><code>case class relevantCollection(
  _id: BSONObjectID,
  irrelevantData: String,
  permissions: Option[Map[String, Map[String, Boolean]]]
)
</code></pre>

<p>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?</p>