title: Insert Multiple JSON files to MongoDB using python
body: <p>The JSON files are as follows a.json,b.json.....z.json (26 json files) </p>
  
  <p>The json format of each of the file looks as:</p>
  
  <pre><code>{
      "a cappella": {
          "word": "a cappella",
          "wordset_id": "5feb6f679a",
          "meanings": [
              {
                  "id": "492099d426",
                  "def": "without musical accompaniment",
                  "example": "they performed a cappella",
                  "speech_part": "adverb"
              },
              {
                  "id": "0bf8d49e2e",
                  "def": "sung without instrumental accompaniment",
                  "example": "they sang an a cappella Mass",
                  "speech_part": "adjective"
              }
          ]
      },
      "A.D.": {
          "word": "A.D.",
          "wordset_id": "b7e9d406a0",
          "meanings": [
              {
                  "id": "a7482f3e30",
                  "def": "in the Christian era",
                  "speech_part": "adverb",
                  "synonyms": [
                      "AD"
                  ]
              }
          ]
      },.........
  }
  </code></pre>
  
  <p>How could I store these in MongoDB such that if queried with <code>word</code> the results shows <code>meanings</code>,<code>synonyms</code>(if available)?</p>
  
  <p>I have never used Mongo on how to approach, but the same was done with SO suggestions for a single json file in mysql as:</p>
  
  <p>**cursor has db connection</p>
  
  <pre><code>with open('a.json') as f:
      d = json.load(f)
  
  for word in d:
      word_obj = d[word]
      wordset_id = word_obj['wordset_id']
  
      sql = "INSERT INTO Word (word, wordset_id) VALUES (%s, %s)"
      values = (word, wordset_id)
      cursor.execute(sql, values)
      conn.commit()
  </code></pre>
  
  <p>similarly to store meanings and synonyms as different tables,</p>
  
  <p>But as suggetsed I guess this would become better if MongoDB is used</p>