I would like to connect to MongoDB from a Python script and write data directly onto it. Would like the DB to be filled like so:
John
Titles Values
color black
age 15
Laly
Titles Values
color pink
age 20
Currently, it’s written to a .csv file like following, but would like to write it like so to MongoDB:
import csv
students_file = open(‘./students_file.csv’, ‘w’)
file_writer = csv.writer(students_file)
…
file_writer.writerow([name_title]) #John
file_writer.writerow([‘Titles’, ’Values’])
file_writer.writerow([color_title, color_val]) #In first column: color, in second column: black
file_writer.writerow([age_title, age_val]) #In first column: age, in second column: 15
What would be the right approach to connecting to MongoDB using Python, and write strings directly to MongoDB?
Thank you in advance, and will be sure to upvote/accept answer