title: Loading JSON data in mongodb using sparksql
body: <p>I have a JSON file and i want to load the same into MongoDB using Spark SQL. I had the way of loading individual elements into a collection like below </p>
  
  <pre><code>val mongoClient = MongoClient(127.0.0.1, 27017)
  val collection = mongoClient(dbname)(collection_name)
  for (a &lt;- 1 to 10) {
    collection.insert {
      MongoDBObject("id" -&gt; a.toString,
        "age" -&gt; (10 + a),
        "description" -&gt; s"description $a",
        "enrolled" -&gt; (a % 2 == 0),
        "name" -&gt; s"Name $a")
    }
  </code></pre>
  
  <p>Since MongoDB already stores the data in JSON format, is there any way to load my JSON file directly ? </p>