mongodb contains 2 collection with 5 fields each:
{
"channel details": c,
"playlist details": p,
"video_ids": v_id,
"video details": v,
"comment details"
I am trying to push each field in a separate table in MySQL. e.g. all fields in channel details from both collection to channel details table using Python in Jupyter notebook
in collection channel details contains these fields
mysql table for channel details
mydb = client["Youtubehar_DB"]
collection=mydb['youtube_data']
collection.find({},{"channel details":1,"_id":0})
df4=pd.DataFrame(collection.find({},{"channel details":1,"_id":0}))
df4
channel details
0 [{'Channel_id': 'U', 'Channel_name': 'Cone Ice...
1 [{'Channel_id': 'U', 'Channel_name': 'Vj Siddh...
sql = "INSERT INTO channel_details (channel_id, Channel_name, Playlist_id, Subscribers, Views, Total_videos, Description, Country) VALUES (%s, %s, %s, %s, %s, %s, %s, %s)"
for i in range(0,len(df4)):
cur.execute(sql,tuple(df4.iloc[i]))
myconnection.commit()
TypeError: sequence item 0: expected str instance, dict found