BSON Error Connecting to MongoDB from Spark

Viewed 14

Following the instructions to connect to Mongo, I get the following error

Uncaught exception: org/bson/BsonValue (java.lang.NoClassDefFoundError)

Here is my code:

val user = "<>"
val pwd = "<>"

val url = s"mongodb://$user:$pwd@<address>"

spark.conf.set("spark.mongodb.read.connection.uri", url)
spark.conf.set("spark.mongodb.read.database", "<db>")

val df = spark.read.format("mongodb")
.option("database", "<db>")
.option("collection", "<collection>").load()

What am I doing wrong?

0 Answers
Related