Created
April 21, 2017 10:56
-
-
Save mizvol/227a2e29ee1ade03a5696c5d678a2839 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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