databricks connecting to mongodb atlas data source


First we create a notebook and then we install the require python library for accessing mongodb atlas.


%pip install pymongo




Then we obtain the require connection string for mongodb by going into 






Next, you setup the require datasource and connection string by clicking on add code. 


connectionString="mongodb+srv://your-user-name:your-password@cluster0.psk0yd7.mongodb.net/?retryWrites=true&w=majority&appName=Cluster0"

database="sample_supplies"
collection="sales"


df = spark.read.format("com.mongodb.spark.sql.DefaultSource") \
       .option("database", database) \
       .option("spark.mongodb.input.uri", connectionString) \
       .option("collection", collection) \
       .load()

display(df)

Run the code to get connected, pull out all the data and then display it









Comments

Popular posts from this blog

gemini cli getting file not defined error

NodeJS: Error: spawn EINVAL in window for node version 20.20 and 18.20

vllm : Failed to infer device type