This is how a typical document in my collection is structured:
{u'_id': ObjectId('58645996fa36ac0b9f0e738d'),
u'alias': u'loco_ono',
u'artist': u'ONO’,
u'date_time': datetime.datetime(2016, 12, 29, 0, 32, 22, 723000),
u'followers': [{u'permalink': u'pschedelicsuperfuzz',
u'plan': u'Free'},
{u'permalink': u'd-miller',
u'plan': u'Free'}],
u'followers_count': 60,
u'last_modified': u'2016/10/17 18:53:09 +0000',
u'plan': u'Pro'}
How can I iterate through every document in my collection and write to a CSV file the following information for each iteration using pymongo?
Artist | Follower | Count
loco_ono | pschedelicsuperfuzz | 1
loco_ono | d-miller | 1
So far I have this:
import pymongo
from pymongo import MongoClient
mongo_client = MongoClient()
db = mongo_client.soundcloud_db
artist_followers = db.artist_followers
I'm not sure how to iterate through the artist_followers collection correctly and retrieve only the 'permalink' field values from the 'followers' array for each artist to output in the format described above.
for item in artist_followers: print itemyet?