Skip to content

Instantly share code, notes, and snippets.

@mizvol
Created April 21, 2017 10:56
Show Gist options
  • Save mizvol/227a2e29ee1ade03a5696c5d678a2839 to your computer and use it in GitHub Desktop.
Save mizvol/227a2e29ee1ade03a5696c5d678a2839 to your computer and use it in GitHub Desktop.
import pymongo as pm
client = pm.MongoClient()
db = client.instagram
followerIds = db.followerIds
pipeline = [{"$unwind": "$follows"}]
relationships = list(followerIds.aggregate(pipeline))
userIds = list(followerIds.aggregate([{"$match": {"follows": {"$exists": True}}},{"$project": {"_id": 1}}]))
edgesList = []
for relationship in relationships:
edgesList.append(tuple([str(relationship['_id']), str(relationship['followers']), 'followed_by']))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment