title: How to export mongo data into csv using pymongo?
body: <p>My code :</p>
  
  <pre><code>data = db.get_collection('activity_tracker').find({"companyId" : "527d4b23-347a-4ad2-81d8-dfd66af5631a", 'userEmail':{'$ne':'abc@xyz.in'}})
  
  with open('asdxk.csv', 'w') as outfile:
  
      fields = ['companyId', 'userEmail']
      writer = csv.writer(outfile, fields)
      for post in data:
          writer.writerow([post])
  </code></pre>
  
  <p>Problem statement :</p>
  
  <p>Using above code I am exporting data to CSV file as a junk but what i want to do is companyID  and  userEmail details should be export to csv as row and column format. Header name should be companyID and  userEmail.</p>