title: Importing Json to MongoDB with Python
body: <p>I am currently trying to import a lot of json files to Mongodb, some of the jsons are simple with just object:Key:value and those json uploads I can query just fine within python.
  Example</p>
  <pre><code>[
      {
          &quot;platform_id&quot;: 28,
          &quot;mhz&quot;: 2400,
          &quot;version&quot;: &quot;1.1.1l&quot; 
      }
  [
  </code></pre>
  <p>The MongoDB compass shows it <a href="https://i.stack.imgur.com/bSVDy.png" rel="nofollow noreferrer">like this</a></p>
  <p>Where the problem lies in one of the tools, creates a doc in Mongo, that I can not figure out how to query. The tool creates a json with system information, that's being pushed into the db. Example:
  ...</p>
  <pre><code>{
      &quot;systeminfo&quot;: [
          {
              &quot;component&quot;: &quot;system board&quot;,
              &quot;description&quot;: &quot;sys board123&quot;
          },
          {
              &quot;component&quot;: &quot;bios&quot;,
              &quot;version&quot;: &quot;xyz&quot;,
              &quot;date&quot;: &quot;06/28/2021&quot;
          },
          {
              &quot;component&quot;: &quot;processors&quot;,
              &quot;htt&quot;: true,
              &quot;turbo&quot;: false
          },
  </code></pre>
  <p>...
  etc for a total of 23 objects.</p>
  <p>If I push it directly into Mongo DB it looks like <a href="https://i.stack.imgur.com/tiDRM.png" rel="nofollow noreferrer">this in compass</a></p>
  <p>So the question is, is there a way to collapse the hardware json one level or a way to query the db. I have found a way to collapse the json, but it moves each value pair into a new dictionary for upload and every parameter is done individually. Not sustainable as the tool is constantly adding new fields and need my app to handle the changes</p>
  <p>Here is an example of the hw query, using same pattern works fine for   the other collection</p>
  <pre><code>db=myclient[('db_name'])]
  col = db[(HW_collection]
  myquery={&quot;component&quot;:&quot;processors&quot;}
  mydoc=col.find(myquery)
  </code></pre>