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

0 votes

I'm try to import json in the file to mongodb using pyspark after connection pyspark with mongodb, I'm using Ubuntu, my file in (file:///home/user/Downloads/newdb/hale.json) I write it like this ('home/user/Downloads/newdb/hale.json'),

I want to try using this code but in JSON

df = = '/home/ahmad/Downloads/newdb/hale.csv', header=True, inferSchema=True)


Sep 8 in Python by Ahmed
• 260 points

edited Sep 9 by Omkar 31 views

1 answer to this question.

0 votes

You can use the same format as in your question but replace csv with json. 

df = = '/home/ahmad/Downloads/newdb/hale.json', header=True, inferSchema=True)
answered Sep 9 by Karan
Thank you, I did this code but doesn't work :(
Hey @Ahmed. Can you share the error that you got?

Related Questions In Python

0 votes
1 answer

How to download a file over HTTP using Python?

In Python 2, use urllib2 which comes ...READ MORE

answered Oct 18, 2018 in Python by SDeb
• 13,160 points
0 votes
1 answer

How to check latest change time of each file using glob in python?

You can get the changing time from ...READ MORE

answered Jan 2 in Python by Omkar
• 67,520 points
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 in Python by Nymeria
• 3,520 points
0 votes
1 answer

How to read data from a text file using Python?

Refer to the below example where the ...READ MORE

answered May 12 in Python by Sushma
+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 6 in Python by Neha
• 330 points

edited Jul 8 by Kalgi 238 views
+1 vote
1 answer

How to read hdfs file using python?

subprocess.Popen(["hadoop", "fs", "-cat", "/path/to/myfile"], stdout ...READ MORE

answered Dec 6, 2018 in Python by Omkar
• 67,520 points
+2 votes
3 answers

How can I play an audio file in the background using Python?

down voteacceptedFor windows: you could use  winsound.SND_ASYNC to play them ...READ MORE

answered Apr 3, 2018 in Python by charlie_brown
• 7,720 points