How to create index for dic in mongodb with python?
<p>I have some objects like:</p>

<pre><code>{
    'id':1
    'claims':{
        'c1':{xxxxx},
        'c8':{xxxxx},
        'c20':{xxxxx}
    }
}
</code></pre>

<p>if I use <code>d.create_index([('claims', 1)])</code> directly, it will use whole <code>{'c1':{xxxxx},'c8':{xxxxx},'c20':{xxxxx}}</code> as index which is not what I want. I want just use 'c1', 'c8', 'c20' as keys. I read the document said that if it is an array like:</p>

<pre><code>{
    'id':1
    'claims':[
        'c1':{xxxxx},
        'c8':{xxxxx},
        'c20':{xxxxx}
    ]
}
</code></pre>

<p>It will be possible. And I want to know if this can be done when it is a dict. or how can I convert it into an array?</p>

<p>The way of doing that is as follows:</p>

<pre><code>db.collection.createIndex( { 'claims.c1':1, 'claims.c8':1, 'claims.c20':1 } )
</code></pre>

python arrays mongodb dictionary indexing