I'm practicing mongoDB with a small tweets dataset right now and don't have much experience with $graphLookup. For each document that matches, I'm trying to find the screen_name of the user the tweet is replying to, and if that tweet is also a retweet of another tweet, then display the user screen_name of that tweet too, so on and so forth up the hierarchy of retweets until the original tweet.
A standard document of retweets in the dataset looks like this
`
{
_id: ObjectId("5c8eccb0caa187d17ca62408"),
text: 'RT @Philanthropy: How should nonprofit groups measure their social-media efforts? A new podcast from @afine http://ht.ly/2yFlS',
in_reply_to_status_id: null,
retweet_count: null,
contributors: null,
created_at: 'Thu Sep 02 18:11:24 +0000 2010',
geo: null,
source: 'web',
retweeted_status: {
text: 'How should nonprofit groups measure their social-media efforts? A new podcast from @afine http://ht.ly/2yFlS',
in_reply_to_status_id: null,
retweet_count: null,
contributors: null,
created_at: 'Thu Sep 02 18:09:14 +0000 2010',
geo: null,
source: '<a href="http://www.hootsuite.com" rel="nofollow">HootSuite</a>',
coordinates: null,
in_reply_to_screen_name: null,
truncated: false,
entities: {
user_mentions: [
{
indices: [ 83, 89 ],
screen_name: 'Afine',
name: 'Allison Fine',
id: 15016599
}
],
urls: [
{
indices: [ 90, 108 ],
url: 'http://ht.ly/2yFlS',
expanded_url: null
}
],
hashtags: []
},
retweeted: false,
place: null,
user: {
friends_count: 2800,
profile_sidebar_fill_color: 'faf5eb',
location: 'Washington, D.C.',
verified: false,
follow_request_sent: null,
favourites_count: 2,
profile_sidebar_border_color: 'faf5eb',
profile_image_url: 'http://a2.twimg.com/profile_images/669725690/twitterprofilepic_normal.jpg',
geo_enabled: false,
created_at: 'Wed Dec 05 19:13:58 +0000 2007',
description: "The Chronicle of Philanthropy's official Twitter page, updated by Peter Panepento",
time_zone: 'Central Time (US & Canada)',
url: 'http://philanthropy.com',
screen_name: 'Philanthropy',
notifications: null,
profile_background_color: 'e7dfd3',
listed_count: 1679,
lang: 'en',
profile_background_image_url: 'http://a3.twimg.com/profile_background_images/71652755/bgv3.jpg',
statuses_count: 6492,
following: null,
profile_text_color: '572b0e',
protected: false,
show_all_inline_media: false,
profile_background_tile: false,
name: 'Philanthropy',
contributors_enabled: false,
profile_link_color: '246a88',
followers_count: 19406,
id: 10880202,
profile_use_background_image: true,
utc_offset: -21600
},
favorited: false,
in_reply_to_user_id: null,
id: Long("22819258393")
},
coordinates: null,
in_reply_to_screen_name: null,
truncated: false,
entities: {
user_mentions: [
{
indices: [ 3, 16 ],
screen_name: 'Philanthropy',
name: 'Philanthropy',
id: 10880202
},
{
indices: [ 101, 107 ],
screen_name: 'Afine',
name: 'Allison Fine',
id: 15016599
}
],
urls: [
{
indices: [ 108, 126 ],
url: 'http://ht.ly/2yFlS',
expanded_url: null
}
],
hashtags: []
},
retweeted: false,
place: null,
user: {
friends_count: 68,
profile_sidebar_fill_color: 'e0ff92',
location: '',
verified: false,
follow_request_sent: null,
favourites_count: 0,
profile_sidebar_border_color: '87bc44',
profile_image_url: 'http://a1.twimg.com/profile_images/1101368689/3f84a22_normal.jpg',
geo_enabled: false,
created_at: 'Thu Jul 15 03:54:39 +0000 2010',
description: '',
time_zone: null,
url: null,
screen_name: 'DerekBechthold',
notifications: null,
profile_background_color: '9ae4e8',
listed_count: 1,
lang: 'en',
profile_background_image_url: 'http://s.twimg.com/a/1282328015/images/themes/theme1/bg.png',
statuses_count: 54,
following: null,
profile_text_color: '000000',
protected: false,
show_all_inline_media: false,
profile_background_tile: false,
name: 'Derek Bechthold',
contributors_enabled: false,
profile_link_color: '0000ff',
followers_count: 24,
id: 166846185,
profile_use_background_image: true,
utc_offset: null
},
favorited: false,
in_reply_to_user_id: null,
id: Long("22819398100")
},
{
_id: ObjectId("5c8eccb0caa187d17ca624ab"),
text: 'RT @ESPNsoccernet: Van der Vaart denies being a failure at Real Madrid: Rafael van der Vaart maintains he was no "failure" at Real Ma... ...',
in_reply_to_status_id: null,
retweet_count: null,
contributors: null,
created_at: 'Thu Sep 02 18:11:44 +0000 2010',
geo: null,
source: '<a href="http://twitter.com/" rel="nofollow">Twitter for iPhone</a>',
retweeted_status: {
text: 'Van der Vaart denies being a failure at Real Madrid: Rafael van der Vaart maintains he was no "failure" at Real Ma... http://bit.com/9d3Gah',
in_reply_to_status_id: null,
retweet_count: null,
contributors: null,
created_at: 'Thu Sep 02 16:53:41 +0000 2010',
geo: null,
source: '<a href="http://twitterfeed.com" rel="nofollow">twitterfeed</a>',
coordinates: null,
in_reply_to_screen_name: null,
truncated: false,
entities: {
user_mentions: [],
urls: [
{
indices: [ 118, 138 ],
url: 'http://bit.com/9d3Gah',
expanded_url: null
}
],
hashtags: []
},
retweeted: false,
place: null,
user: {
friends_count: 0,
profile_sidebar_fill_color: 'e0ff92',
location: null,
verified: false,
follow_request_sent: null,
favourites_count: 0,
profile_sidebar_border_color: '87bc44',
profile_image_url: 'http://a2.twimg.com/profile_images/70131430/espn_normal.jpg',
geo_enabled: false,
created_at: 'Wed Jan 07 15:27:26 +0000 2009',
description: null,
time_zone: null,
url: null,
screen_name: 'ESPNsoccernet',
notifications: null,
profile_background_color: '9ae4e8',
listed_count: 368,
lang: 'en',
profile_background_image_url: 'http://s.twimg.com/a/1282351897/images/themes/theme1/bg.png',
statuses_count: 13447,
following: null,
profile_text_color: '000000',
protected: false,
show_all_inline_media: false,
profile_background_tile: false,
name: 'ESPNsoccernet',
contributors_enabled: false,
profile_link_color: '0000ff',
followers_count: 4669,
id: 18724620,
profile_use_background_image: true,
utc_offset: null
},
favorited: false,
in_reply_to_user_id: null,
id: Long("22814093566")
},
coordinates: null,
in_reply_to_screen_name: null,
truncated: true,
entities: {
user_mentions: [
{
indices: [ 3, 17 ],
screen_name: 'ESPNsoccernet',
name: 'ESPNsoccernet',
id: 18724620
}
],
urls: [],
hashtags: []
},
retweeted: false,
place: null,
user: {
friends_count: 54,
profile_sidebar_fill_color: 'e0ff92',
location: 'Park Triangle Apartments (US)',
verified: false,
follow_request_sent: null,
favourites_count: 2,
profile_sidebar_border_color: '87bc44',
profile_image_url: 'http://a0.twimg.com/profile_images/1066211448/27399ece-83d9-4187-bf0d-04f538d7725c_normal.png',
geo_enabled: false,
created_at: 'Mon Apr 28 23:28:31 +0000 2008',
description: '',
time_zone: 'Quito',
url: null,
screen_name: 'desjef75',
notifications: null,
profile_background_color: '9ae4e8',
listed_count: 0,
lang: 'en',
profile_background_image_url: 'http://s.twimg.com/a/1283397887/images/themes/theme1/bg.png',
statuses_count: 1031,
following: null,
profile_text_color: '000000',
protected: false,
show_all_inline_media: false,
profile_background_tile: false,
name: 'desjef75',
contributors_enabled: false,
profile_link_color: '0000ff',
followers_count: 15,
id: 14577356,
profile_use_background_image: true,
utc_offset: -18000
},
favorited: false,
in_reply_to_user_id: null,
id: Long("22819419400")
}
`
This is the query I have so far
db.tweets.aggregate([{$graphLookup:{from: "tweets", startWith: "$text", connectFromField:"text", connectToField:"retweeted_status.text", as:"Retweets Hierarchy"}}])
But this isn't really showing the screen_name, I'm not really even sure how to that while still matching the text to the fields and I'm so lost any help would be much appreciated.
My ideal result would be something like the image below, where it would show a clear structure from the bottom up.