title: Error while loading data into MongoDB
body: <p>I am trying to load data into MongoDB from Spark below is my code:</p>
  
  <pre><code>import com.databricks.spark.avro._
  import org.apache.spark.{SparkConf, SparkContext}
  import org.apache.spark.sql.SQLContext
  
  import com.mongodb.casbah.{WriteConcern =&gt; MongodbWriteConcern}
  import com.stratio.provider.mongodb._
  import MongodbConfig._  
  
  object test  {
      def main(args: Array[String]) {
  
        val conf = new SparkConf().setAppName("test").setMaster("local[8]")
  
        val sc = new SparkContext(conf)
        val sqlContext = new SQLContext(sc)  
  
        val test= sqlContext.read.avro("file:///Users\\abhis\\Desktop\\Avro\\test")    // test File
          logger.info("Reading test file")
  
        // The avro data is stored in a temporary tables 
        test.registerTempTable("test")    //  test temp table
  
        val targetData = sqlContext.sql("SELECT * From test")  // my code is running fine till here
  
        // Configuration of MongoDb to save the data into collection
          val targetOutputBuilder = MongodbConfigBuilder(Map(Host -&gt; List("localhost:27017"), Database -&gt; "subs", Collection -&gt; "target", SamplingRatio -&gt; 1.0, WriteConcern -&gt; MongodbWriteConcern.Normal, SplitKey -&gt; "_id", SplitSize -&gt; 8))
  
          val writeConfig = targetOutputBuilder.build()
  
          // Writing data into the mongoDb table
          targetData.saveToMongodb(writeConfig)
  
      }
    }
  </code></pre>
  
  <p>I am running the code in Intellij IDEA and added these jar as dependencies:</p>
  
  <ul>
  <li>casbah-commons_2.10-2.8.0 </li>
  <li>casbah-core_2.10-2.8.0</li>
  <li>casbah-core_2.10-2.8.0 </li>
  <li>mongo-java-driver-2.13.0</li>
  <li>spark-mongodb-core-0.8.7</li>
  </ul>
  
  <p>I am getting below error:</p>
  
  <pre><code>java.lang.NoClassDefFoundError: Could not initialize class com.mongodb.MongoClient
      at com.mongodb.casbah.MongoClient$.apply(MongoClient.scala:176)
      at com.stratio.provider.mongodb.MongodbClientFactory$.createClient(MongodbClientFactory.scala:43)
      at com.stratio.provider.mongodb.writer.MongodbWriter.&lt;init&gt;(MongodbWriter.scala:40)
      at com.stratio.provider.mongodb.writer.MongodbBatchWriter.&lt;init&gt;(MongodbBatchWriter.scala:32)
      at com.stratio.provider.mongodb.MongodbDataFrame$$anonfun$saveToMongodb$1.apply(mongodbFunctions.scala:61)
      at com.stratio.provider.mongodb.MongodbDataFrame$$anonfun$saveToMongodb$1.apply(mongodbFunctions.scala:59)
      at org.apache.spark.rdd.RDD$$anonfun$foreachPartition$1$$anonfun$apply$33.apply(RDD.scala:920)
      at org.apache.spark.rdd.RDD$$anonfun$foreachPartition$1$$anonfun$apply$33.apply(RDD.scala:920)
      at org.apache.spark.SparkContext$$anonfun$runJob$5.apply(SparkContext.scala:1858)
      at org.apache.spark.SparkContext$$anonfun$runJob$5.apply(SparkContext.scala:1858)
      at org.apache.spark.scheduler.ResultTask.runTask(ResultTask.scala:66)
      at org.apache.spark.scheduler.Task.run(Task.scala:89)
      at org.apache.spark.executor.Executor$TaskRunner.run(Executor.scala:214)
      at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
      at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
      at java.lang.Thread.run(Thread.java:745)
  16/05/15 22:13:57 ERROR Executor: Exception in task 2.0 in stage 4.0 (TID 18)
  java.lang.IllegalAccessError: tried to access method org.bson.types.ObjectId.&lt;init&gt;(III)V from class com.mongodb.Bytes
      at com.mongodb.Bytes.&lt;clinit&gt;(Bytes.java:219)
      at com.mongodb.Mongo.&lt;clinit&gt;(Mongo.java:74)
      at com.mongodb.casbah.MongoClient$.apply(MongoClient.scala:176)
      at com.stratio.provider.mongodb.MongodbClientFactory$.createClient(MongodbClientFactory.scala:43)
      at com.stratio.provider.mongodb.writer.MongodbWriter.&lt;init&gt;(MongodbWriter.scala:40)
      at com.stratio.provider.mongodb.writer.MongodbBatchWriter.&lt;init&gt;(MongodbBatchWriter.scala:32)
      at com.stratio.provider.mongodb.MongodbDataFrame$$anonfun$saveToMongodb$1.apply(mongodbFunctions.scala:61)
      at com.stratio.provider.mongodb.MongodbDataFrame$$anonfun$saveToMongodb$1.apply(mongodbFunctions.scala:59)
      at org.apache.spark.rdd.RDD$$anonfun$foreachPartition$1$$anonfun$apply$33.apply(RDD.scala:920)
      at org.apache.spark.rdd.RDD$$anonfun$foreachPartition$1$$anonfun$apply$33.apply(RDD.scala:920)
      at org.apache.spark.SparkContext$$anonfun$runJob$5.apply(SparkContext.scala:1858)
      at org.apache.spark.SparkContext$$anonfun$runJob$5.apply(SparkContext.scala:1858)
      at org.apache.spark.scheduler.ResultTask.runTask(ResultTask.scala:66)
      at org.apache.spark.scheduler.Task.run(Task.scala:89)
      at org.apache.spark.executor.Executor$TaskRunner.run(Executor.scala:214)
      at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
      at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
      at java.lang.Thread.run(Thread.java:745)
  </code></pre>