![how to download mongodb how to download mongodb](https://help.hcltechsw.com/sametime/11.0.2/admin/Images/mongodb_download.png)
To save, we need to use a write and save method as shown in the below code.
![how to download mongodb how to download mongodb](https://www.how2shout.com/linux/wp-content/uploads/2021/07/Download-MongoDB-Compass-for-Ubuntu-20.04.jpg)
Here we are going to save the dataframe to the mongo database table which we created earlier. Step 4: To Save Dataframe to MongoDB Table
![how to download mongodb how to download mongodb](https://media.geeksforgeeks.org/wp-content/uploads/20210131003924/Screenshot249.png)
Here we are going to view the data top 5 rows in the dataframe as shown below. Here we will read the schema of the stored table as a dataframe, as shown below. As shown above, we import the Row from class. Here we will create a dataframe to save in a MongoDB table for that The Row class is in the pyspark.sql submodule. Step 2: Create Dataframe to store in MongoDB Note: we need to specify the mongo spark connector which is suitable for your spark version. config('', ':mongo-spark-connector_2.12:3.0.1') \Īs shown in the above code, If you specified the and configuration options when you started pyspark, the default SparkSession object uses them. In this scenario, we are going to import the pyspark and pyspark SQL modules and create a spark session as below:
#How to download mongodb how to#
Recipe Objective: How to Save a DataFrame to MongoDB in Pyspark?