mongodb regex embeded search
<p>My data looks like this:</p>

<pre><code>blade = {
    'model': 'FW254',
    'items':{
              'a': {'time':5, 'count':7},
              'b': {'time':4, 'count':8},
              'c': {'time':2, 'count':9}
    }
}
</code></pre>

<p>I want to do something like this:</p>

<pre><code>collection.find({"items./.*/.time": { "$gte":4}})
</code></pre>

<p>here the element /.*/ is the regex to match 'a', 'b', 'c'</p>

<p>Of course this won't work. My goal is to find the blades with embedded time >= 4. Is that possible? thanks!</p>

<p>Where did you read about using a regex in a spot like that?</p>

<p>You should recosider the structure of you data and turns <code>items</code> into an array allowing you to use <a href="https://docs.mongodb.com/v3.2/reference/operator/query/elemMatch/#op._S_elemMatch" rel="nofollow"><code>$elemMatch</code></a></p>

<pre><code>{ "_id" : ObjectId("58071dd31f4fbf7309ae639a"), "model" : "FW254", 
  "items" : [ { "name": "a", "time" : 5, "count" : 7 },
              { "name": "b", "time" : 4, "count" : 8},
              { "name" : "c", "time" : 2, "count" : 9 }
       ] }

collection.find({items: {$elemMatch: {'time': 4}}})
</code></pre>

python regex mongodb nested