I am trying to create network map based of off twitter user mentions. I am storing the data in MongoDB and cannot figure out how to remove unwanted users.
Example db documents:
{
'user': 'user1'
'mentioned_users: ['user2', 'user3']
}
{
'user': 'user2'
'mentioned_users: ['user1', 'user3']
}
Example desired output:
{
'user': 'user1'
'mentioned_users': ['user2']
}
{
'user': 'user2'
'mentioned_users': ['user1']
}
user3 exists in both user1 and user2 list of mentioned users, however user3 is extraneous because user3 does not have their own document in the collection.
I need either a filter using db.collection.find() or other method so that I can get rid of all of the extraneous users.
Is there an easy way to do this with pymongo, or should I create a python solution?