title: writeStream proccesing data to mongodb
body: <p>I am trying to writeStream processing data(structured streaming data) to mongodb. I can send data from kafka to spark and I can process the data. But I can't send the data to mongodb from spark. and I am getting this error</p>
  <pre><code>&lt;console&gt;:55: error: value map is not a member of org.apache.spark.sql.Row
          val df3 = rdd.map({ case (word: String, count: Int)
  </code></pre>
  <pre><code>    import org.apache.spark.sql.{functions =&gt; f}
      import org.apache.spark.sql.types._
      import org.apache.spark.sql.SparkSession
      import org.apache.log4j.{Logger, Level}
      import org.apache.spark.sql.streaming.Trigger
      import com.mongodb.spark._
      import com.mongodb.spark.sql._
      import org.apache.spark.streaming._
      import com.mongodb.spark.config._
      import com.mongodb.spark.MongoSpark
      
      val spark = SparkSession.builder().master(&quot;localhost&quot;).appName(&quot;ReadFromKafka&quot;).getOrCreate()
  
      import spark.implicits._
          
      val df = spark.readStream.format(&quot;kafka&quot;).option(&quot;kafka.bootstrap.servers&quot;, &quot;IP:9092&quot;).option(&quot;subscribe&quot;, &quot;test&quot;).load()
  
      val df2 = df.select($&quot;key&quot;.cast(StringType), $&quot;value&quot;.cast(StringType))
      
      val df3 = df2.select($&quot;value&quot;).as[String].flatMap(_.split(&quot;\\W+&quot;)).groupBy(&quot;value&quot;).count().sort(f.desc(&quot;count&quot;))   
          
      case class WordCount(word: String, count: Int)
  
      df3.foreach({ rdd =&gt;
      import spark.implicits._
      val df3 = rdd.map({ case (word: String, count: Int)
              =&gt; WordCount(word, count) }).toDF()
      df3.write.mode(&quot;append&quot;).mongo()
      })
  </code></pre>