Hey @Kirki maybe its late but I will try to help you or others to create these connections
First thing make sure you have installed inside your cluster the connector
org.mongodb.spark:mongo-spark-connector_2.12:3.0.1
You can use directly in your spark.read sentence like that
df = spark.read.format("mongodb") \
.option("uri", "mongodb://<your-ec2-ip>:27017/") \
.option("database", "mydatabase") \
.option("collection", "mycollection") \
.load()
or
df = spark.read.format("mongodb") \
.option("spark.mongodb.input.uri", "mongodb://<your-ec2-ip>:27017/mydatabase.mycollection") \
.load()
Set it in the Spark config of your cluster:
spark.mongodb.input.uri mongodb+srv://<user>:<pass>@<cluster>/
spark.mongodb.output.uri mongodb+srv://<user>:<pass>@<cluster>/
Try connecting directly from a Databricks notebook:
%sh
nc -zv <ec2-ip> 27017
At the cluster is an EC2 so:
Make sure MongoDB listens on 0.0.0.0 and your EC2 allows inbound connections on port 27017
Hope this helps, ๐
Isi