title: How to read data from mongo to sparkjava?
body: <p>I have a problem when I read data from mongo to my sparkJava project.
  I want to take all the data from rdd, convert it to &quot;User&quot; and save it in a users list.
  I try to run over my rdds with foreach but it doesn't work, so I try it with map but still nothing happened, and I can't read the data from rdd.
  I know it's possible to do it with parallelize but I don't know how...</p>
  <p>my code:</p>
  <pre><code>SparkSession spark = SparkSession.builder()
          .master(&quot;local&quot;)
          .appName(&quot;MongoSparkConnectorIntro&quot;)
          .config(&quot;spark.mongodb.input.uri&quot;, &quot;mongodb://127.0.0.1/users.todos&quot;)
          .config(&quot;spark.mongodb.output.uri&quot;, &quot;mongodb://127.0.0.1/users.todos&quot;)
          .getOrCreate();
  
  JavaSparkContext jsc = new JavaSparkContext(spark.sparkContext());
  
  JavaMongoRDD&lt;Document&gt; rdd = MongoSpark.load(jsc);
  
  Gson gson = new Gson();
  
  rdd.map(r -&gt; {
      User user = gson.fromJson(r.toJson(), User.class);
      users.add(user);
      return null;
  });
  </code></pre>