How to save the import csv file to mongodb using pyspark or python

0 votes

I have this code, and I want to save the import csv file to mongodb using pyspark but I have 43 error if there another way :

from pyspark.sql import SparkSession
my_spark = SparkSession \
     .builder \
     .appName("myApp") \
     .config("spark.mongodb.input.uri", "mongodb://127.0.0.1/testtt.coll") \
     .config("spark.mongodb.output.uri", "mongodb://127.0.0.1/testtt.coll") \
     .getOrCreate()

df = spark.read.csv(path = '/home/user/Desktop/testtt.csv', header=True, inferSchema=True)



 my problem with is code:
 
df.write.format("com.mongodb.spark.sql.DefaultSource").mode("append").option("database","testtt").option("collection", "coll").save()
Oct 9, 2019 in Python by Ahmed
• 310 points
2,070 views
Hey @Ahmed!

It is difficult to find the problem without the error log. Please share the error log.

No answer to this question. Be the first to respond.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.

Related Questions In Python

0 votes
1 answer

How to import json file to mongodb using pyspark (or python)?

You can use the same format as ...READ MORE

answered Sep 9, 2019 in Python by Karan
1,644 views
0 votes
1 answer

how can i extact all the links from a website using python and save it in a csv file ?

Hi, @Shubham, Web scraping is the technique to ...READ MORE

answered Jun 16, 2020 in Python by Gitika
• 65,910 points
3,747 views
0 votes
1 answer

How to import an image into a csv file using python?

I am sure you are aware CSV ...READ MORE

answered Jun 25, 2020 in Python by Bhanu Kumar
7,265 views
0 votes
1 answer

How to use read a WSDL file from the file system using Python suds?

Hi, good question. It is a very simple ...READ MORE

answered Jan 21, 2019 in Python by Nymeria
• 3,560 points
7,641 views
0 votes
1 answer

How to find the value of a row in a csv file in python?

If you want to find the value ...READ MORE

answered May 20, 2019 in Python by Sanam
18,482 views
–1 vote
2 answers
+2 votes
1 answer
0 votes
2 answers
+1 vote
2 answers

how can i count the items in a list?

Syntax :            list. count(value) Code: colors = ['red', 'green', ...READ MORE

answered Jul 7, 2019 in Python by Neha
• 330 points

edited Jul 8, 2019 by Kalgi 4,007 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP