Django csv file

22 views
Skip to first unread message

Cigi Sebastine

unread,
Mar 12, 2019, 7:14:20 AM3/12/19
to django...@googlegroups.com

Hi all

I am trying to insert data from csv file to mongodb4 using python3.7 (Bulk data insertion 47lakhs records)
i need to implement in django
Can please anyone share ur idea

import pandas as pd
import json

mng_client = MongoClient('localhost', 27017)
mng_db = mng_client['testcsv']
collection_name = mng_db['datastore']
db_cm = mng_db['datastore']

df = pd.read_csv('filepath',encoding = 'ISO-8859-1') # loading csv file
#dfstr = df.to_json('testjson1.json')
data_json = json.loads( df.to_json())
db_cm.insert_many(data_json)

Ryan Nowakowski

unread,
Mar 12, 2019, 3:12:40 PM3/12/19
to django...@googlegroups.com
If I were you, I'd work through the Django tutorial first. Then ask specific questions if you have any.

Chetan Ganji

unread,
Mar 12, 2019, 6:12:21 PM3/12/19
to django...@googlegroups.com
I would suggest you use transactions for inserting those many documents. 
https://www.mongodb.com/transactions

Django ORM does not support MongoDB. So, you can't use models/ORM/Class Based Views of Django with mongo. 
Only way I know to use Mongo with Django is function based views. There are some third party MONGO ORMS for django, but I never used them so far, so can't comment on how good they are or are not. Do your R&D and find it out ;-) 

I hope this helps you. Cheers!


Regards,
Chetan Ganji
+91-900-483-4183


--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/89E98305-6AEC-4A82-9839-E86760DC3AB2%40fattuba.com.
For more options, visit https://groups.google.com/d/optout.

Cigi Sebastine

unread,
Mar 13, 2019, 7:44:16 AM3/13/19
to django...@googlegroups.com

Chetan Ganji

unread,
Mar 13, 2019, 7:48:46 AM3/13/19
to django...@googlegroups.com
Reply all
Reply to author
Forward
0 new messages