I'm trying to write some data into CSV format using fetched data from MongoDB, with Mongopy. Currently, the headers are currently set, and the problem is that the actual data is not being inserted into the CSV file. here is the code snippet :
from pymongo import MongoClient
import csv
import os
conn = pymongo.MongoClient()
db = conn.clixster_dev
cursor = db.channels.find({},{'_id':0 , 'company-reg-no':0, 'isdel':0 , 'last_off':0 , 'last_on':0 , 'online':0 , 'password':0 , 'psotcode':0 , 'state':0 , 'subagent':0})
outfile = open( "asdxk.csv", "w" )
# get a csv writer
writer = csv.writer( outfile )
# write header
writer.writerow(['postcode', 'upline', 'cit_state', 'contact_person', 'contact_no','nominal_level', 'credit', 'level', 'account_holder', 'merchantid', 'email', 'bank', 'reg_date' ,'address','acc_no','company_name'])
# write data
[ writer.writerow(x) for x in cursor ]
# close file
outfile.close()
Any consideration is appreciated,