title: How do I load a json file into mongoDB?
body: <p>I have a json file with some information in this format:</p>
  
  <pre><code>{ "_id" : ObjectId("xxx"), "date_time" : ISODate("2014-06-11T19:16:45Z"), "name" : "AAA", "phone_no" : "111", "address" : "BBB", "categories" : "CCC" }  
  { "_id" : ObjectId("yyy"), "date_time" : ISODate("2014-06-11T19:16:44Z"), "name" : "EEE", "phone_no" : "222", "address" : "FFF", "categories" : "GGG" }  
  { "_id" : ObjectId("zzz"), "date_time" : ISODate("2014-06-11T19:16:46Z"), "name" : "HHH", "phone_no" : "333", "address" : "III", "categories" : "JJJ" }
  </code></pre>
  
  <p>The code I'm using is this: </p>
  
  <pre><code>db = pymongo.MongoClient().test  
  path ='/home/files'  
  for f in listdir(path):  
      filepath = path+'/'+f  
      data = []     
      for line in open(filepath):  
          try:  
              data.append(json.loads(line))  
          except:  
              pass  
      db.temp.insert(data)  
  </code></pre>
  
  <p>This results in an error stating empty bulk write is not possible. Basically, the <code>json.loads(line)</code> never works. Is it the format of the json file that's the issue? Should the variable 'data' be declared some other way? </p>
  
  <p>How do I load this file into <strong>mongoDB</strong>?</p>