title: Writing scala/spark info into MongoDB
body: <p>I have a log data having data like </p>
  
  <pre><code>Started by timer
  ...
  ...
  Finished: SUCCESS
  </code></pre>
  
  <p>For each log data ,the log status(here "Finished") and the status("SUCCESS") needs to written into MongoDB.</p>
  
  <pre><code>case class Logs(status:String,statusCode:String)
  
  def main(args:Array[String]){
  
       val sc= new SparkContext("local[*]","MongoDB")
       val lines=sc.textFile("log1.txt")
       val pairs=lines.filter(value=&gt;value.startsWith("Finished")).
       map(lines=&gt;lines.split(": ")).
       map(lines=&gt;(lines(0).toString(),lines(1).toString())).
  
      for(keyAndValue&lt;-pairs){
        println("key: "+va._1+" has val: "+va._2)
      }
  </code></pre>
  
  <p>I am able to get the values correctly.</p>
  
  <p>Now I would like to store them as key and value in MongoDB like ("Finished","SUCCESS"), in a particular database for a collection.</p>
  
  <p>I created mongodb configuration as below:</p>
  
  <pre><code> val spark = SparkSession.builder()
  .master("local")
  .appName("MongoSparkConnectorIntro")
  .config("spark.mongodb.input.uri", "mongodb://localhost:27017/test.test")
  .config("spark.mongodb.input.readPreference.name", "secondaryPreferred")
  .config("spark.mongodb.output.uri", "mongodb://127.0.0.1/test.test")
  .getOrCreate()
  </code></pre>
  
  <p>How do I use the class I have created to store the values?</p>
  
  <p>Am I missing any additional configuration, or need to put the data differently in  the database. </p>
  
  <p>I have tried to save the info into Mongo using the below snippet , but, it is indicating that 'write is not a member of RDD' .</p>
  
  <pre><code>pairs.foreachRDD({ rdd =&gt;
  import spark.implicits._
  val matching = rdd.map({ case (status: String, statusCode: String)
  =&gt; Logs(status, statusCode) })
  matching.write.mode("append").mongo()
  })
  </code></pre>
  
  <p>Any help will be much appreciated.</p>