Unable to Read Collection/Files from MongoDB using Azure Databricks
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-31-2025 04:57 PM
Hi there,
Can someone help to read data from MongoDB using Azure Databricks? Surprisingly, I am able to connect from Jupyter Notebook and read data, but not from the Azure Databricks.
1) I have install the required spark-connector packages in the cluster. 2) I have a valid MongoDB Atlas Cluster. 3) I have Spark cluster 13.3 LTS.
I am not even able to read the local database which I have created in Mongo DB Compass which has port 27017.
Can someone please help?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-01-2025 08:04 AM
Hi @simha08,
Can you test connectivity first to the MongoDB? using nc -vz hostname port.
Also please share the code you are using to establish the connection and read data.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
a month ago
I am using following code to read the data from mongoDB using Databricks
from pyspark.sql import SparkSession
spark = SparkSession \
.builder \
.appName("myApp") \
.config("spark.mongodb.connection.uri", "mongodb+srv://username:password@cluster.xxxx.mongodb.net/database.collection") \
.getOrCreate()
df = spark.read.format("mongo").load()

