title: How to Insert new element into existed mongodb and uptate existed document from json file?
body: <p>I have a problem about python and mongodb. I have an existed mongodb wh and a collection basicdata in it. I want to merge json file into that existed mongodb by key "whID". my code as follows:</p>
  
  <pre><code>import json, glob, codecs
  from pymongo import MongoClient
  
  directory = 'json/test/211.json'
  client = MongoClient("localhost", 27017)
  db = client.wh
  
  jsonFiles = glob.glob(directory)
  for file in jsonFiles:
       fwhID = file[10:13] #get the file name as whID in a stupid way
       with codecs.open(file,'r',errors='ignore',encoding='utf-8') as json_file:
            json_data = json.load(json_file)
            db.basicdata.update({"whID": fwhID },json_data, {upsert: true})
            print("Processing Json_data: ",file)
       json_file.close()
  </code></pre>
  
  <p>but I got a error message as follow:</p>
  
  <pre><code>    db.basicdata.update({"whID": fwhID },json_data, {upsert: true})
  NameError: name 'true' is not defined
  </code></pre>
  
  <p>Can anybody could help me? Thanks!!</p>