0

A sample document with user mentions in the tweets dataset I'm working with looks like this. I'm trying to get mongoDB to link the user.screen_name with their mentions in other tweets, if there are any, and go further up the hierarchy if that tweet also mentions someone else.

    {
    _id: ObjectId("5c8eccb2caa187d17ca6b214"),
    text: 'PROMO - Concorra a um Ipad por semana #sorteio Faça seu cadastro e envie seu login para @lepetitpromo RT pls..',
    in_reply_to_status_id: null,
    retweet_count: null,
    contributors: null,
    created_at: 'Thu Sep 02 19:30:31 +0000 2010',
    geo: null,
    source: 'web',
    coordinates: null,
    in_reply_to_screen_name: null,
    truncated: false,
    entities: {
      user_mentions: [
        {
          indices: [ 88, 101 ],
          screen_name: 'lepetitpromo',
          name: 'Le Petit Promo',
          id: 116353452
        }
      ],
      urls: [],
      hashtags: [ { text: 'sorteio', indices: [ 38, 46 ] } ]
    },
    retweeted: false,
    place: null,
    user: {
      friends_count: 39464,
      profile_sidebar_fill_color: 'A32247',
      location: 'SP, Brasil',
      verified: false,
      follow_request_sent: null,
      favourites_count: 546,
      profile_sidebar_border_color: 'e69cd7',
      profile_image_url: 'http://a1.twimg.com/profile_images/1112836301/30480_107192455999355_100001258033161_53885_3288503_n_normal.jpg',
      geo_enabled: true,
      created_at: 'Mon Feb 22 04:34:35 +0000 2010',
      description: 'Promonauta ligada 24hs nas melhores ofertas, sorteios e novidades no TWITTER! - Site http://www.lepetitpromo.com.br - contato: lepetitpromo@gmail.com',
      time_zone: 'Brasilia',
      url: 'http://lepetitpromo.com.br',
      screen_name: 'lepetitpromo',
      notifications: null,
      profile_background_color: '000000',
      listed_count: 683,
      lang: 'en',
      profile_background_image_url: 'http://a3.twimg.com/profile_background_images/141124445/x5293307ec686ccde4688a7b20c51d5a.jpg',
      statuses_count: 49358,
      following: null,
      profile_text_color: 'b393b3',
      protected: false,
      show_all_inline_media: false,
      profile_background_tile: true,
      name: 'Le Petit Promo',
      contributors_enabled: false,
      profile_link_color: '60a9d1',
      followers_count: 57774,
      id: 116353452,
      profile_use_background_image: true,
      utc_offset: -10800
    },
    favorited: false,
    in_reply_to_user_id: null,
    id: Long("22824145700")
  }

Here's the query I have so far:

    db.tweets.aggregate(
  [
    {
      $graphLookup: {
        from: 'tweets',
        startWith: "$user.screen_name",
        connectFromField: 'user.screen_name',
        connectToField: 'entities.user_mentions.screen_name',
        as: 'User Mentions'
      }
    }
  ]
)

But the code above still doesn't return anything, I'm not really sure what I'm getting wrong but any help would be much appreciated.

cooperano
  • 23
  • 4
  • FYI, here's a [mongoplayground.net](https://mongoplayground.net/p/GQia0vX2ryk "CLick me!") using your example doc and aggregation pipeline. You can see that `"User Mentions"` array has a single element, itself, since that matches the `"$graphLookup"` connection criteria. – rickhg12hs Nov 01 '22 at 09:36

0 Answers0