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 Streaming Not Receiving Records in Databricks

vidya_kothavale
New Contributor III


Batch Read (spark.read.format("mongodb")) works fine.
Streaming Read (spark.readStream.format("mongodb")) runs but receives no records.

Batch Read (Works):
df = spark.read.format("mongodb")\
.option("database", database)\
.option("spark.mongodb.read.connection.uri", connectionString)\
.option("collection", collection)\
.schema(schema)\
.load()

Streaming Read (Not Receiving Records):

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

Questions:

Does MongoDB require special settings to enable streaming?
Any known issues with MongoDB change streams on Databricks?

2 REPLIES 2

Alberto_Umana
Databricks Employee
Databricks Employee

Hello @vidya_kothavale,

MongoDB requires the use of change streams to enable streaming. Change streams allow applications to access real-time data changes without polling the database. Ensure that your MongoDB instance is configured to support change streams. Change Streams are available for replica sets and sharded clusters in MongoDB 3.6 and later

@Alberto_Umana Currently, only the records received after streaming started are available; the previous records are missing. Is there any additional steps required?

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