cancel
Showing results forย 
Search instead forย 
Did you mean:ย 
Data Engineering
Join discussions on data engineering best practices, architectures, and optimization strategies within the Databricks Community. Exchange insights and solutions with fellow data engineers.
cancel
Showing results forย 
Search instead forย 
Did you mean:ย 

MongoDB Spark Connector v10.x read error on Databricks 14.3 LTS

pferreira
New Contributor II

Im facing an error when updating DBR from 13.3 LTS to 14.3LTS

Im using the spark:mongo-spark-connector:10.2.1 and running the following script

 

 

 

connectionString = ******
database = *****
collection = *****


spark = SparkSession \
    .builder \
    .master("local") \
    .appName("myAPP") \
    .config("spark.mongodb.read.connection.uri", connectionString) \
    .config("spark.mongodb.write.connection.uri", connectionString) \
    .config('spark.jars.packages', 'org.mongodb.spark:mongo-spark-connector:10.2.1') \
    .getOrCreate()


caDf = spark.read.format("mongodb") \
    .option("connection.uri", connectionString) \
    .option("database", database) \
    .option("collection", collection)\ 
    .load()

 

 

 

And when I run this on a cluster with the DBR 14.3 LTS I get the following error:

 

 

 

Py4JJavaError: An error occurred while calling o433.showString.
: java.lang.NoClassDefFoundError: Could not initialize class com.mongodb.spark.sql.connector.read.MongoScanBuilder
	at com.mongodb.spark.sql.connector.MongoTable.newScanBuilder(MongoTable.java:121)
	at org.apache.spark.sql.execution.datasources.v2.V2ScanRelationPushDown$$anonfun$createScanBuilder$1.applyOrElse(V2ScanRelationPushDown.scala:59)
	at org.apache.spark.sql.execution.datasources.v2.V2ScanRelationPushDown$$anonfun$createScanBuilder$1.applyOrElse(V2ScanRelationPushDown.scala:57)
	at org.apache.spark.sql.catalyst.trees.TreeNode.$anonfun$transformDownWithPruning$1(TreeNode.scala:473)
	at org.apache.spark.sql.catalyst.trees.CurrentOrigin$.withOrigin(origin.scala:83)

 

 

 

thanks in advance

2 REPLIES 2

feiyun0112
Honored Contributor

The following notebook shows you how to read and write data to MongoDB Atlas, 

https://docs.databricks.com/en/_extras/notebooks/source/mongodb.html 

Hi @feiyun0112 
Thank you for your help.

Unfortunatle, that didn't help...
Our code is like its documented and was working with the DBR 13.3 LTS, however, once we upgraded the cluster to DBR 14.3LTS we got this error.

Connect with Databricks Users in Your Area

Join a Regional User Group to connect with local Databricks users. Events will be happening in your city, and you wonโ€™t want to miss the chance to attend and share knowledge.

If there isnโ€™t a group near you, start one and help create a community that brings people together.

Request a New Group