0

I'm new using mongodb and using the function .find() to search documents. Recently I've been working with the tweeter API and I have to do some "queries" regarding the results of my requests.

This one it's a example that I have on my mongodb :

{
  "statuses": [
    {
      "created_at": "Mon Jan 06 23:32:51 +0000 2020",
      "id": 1214329007560253441,
      "id_str": "1214329007560253441",
      "full_text": "#ASEAN needs smart #regulation to boost #financialinclusion as  Unclear rules are hindering #fintech companies from reaching millions \n\n#Finserv #payment #openbanking #Regtech #platform #banking #compliance #dataprotection \n\n@NAR \n\nhttps://t.co/wd0H7zx2rV",
      "truncated": false,
      "display_text_range": [
        0,
        255
      ],
      "entities": {
        "hashtags": [
          {
            "text": "ASEAN",
            "indices": [
              0,
              6
            ]
          },
          {
            "text": "regulation",
            "indices": [
              19,
              30
            ]
          },
          {
            "text": "financialinclusion",
            "indices": [
              40,
              59
            ]
          },
          {
            "text": "fintech",
            "indices": [
              92,
              100
            ]
          },
          {
            "text": "Finserv",
            "indices": [
              136,
              144
            ]
          },
          {
            "text": "payment",
            "indices": [
              145,
              153
            ]
          },
          {
            "text": "openbanking",
            "indices": [
              154,
              166
            ]
          },
          {
            "text": "Regtech",
            "indices": [
              167,
              175
            ]
          },
          {
            "text": "platform",
            "indices": [
              176,
              185
            ]
          },
          {
            "text": "banking",
            "indices": [
              186,
              194
            ]
          },
          {
            "text": "compliance",
            "indices": [
              195,
              206
            ]
          },
          {
            "text": "dataprotection",
            "indices": [
              207,
              222
            ]
          }
        ],
        "symbols": [],
        "user_mentions": [
          {
            "screen_name": "NAR",
            "name": "Nikkei Asian Review",
            "id": 436429668,
            "id_str": "436429668",
            "indices": [
              225,
              229
            ]
          }
        ],
        "urls": [
          {
            "url": "https://t.co/wd0H7zx2rV",
            "expanded_url": "https://asia.nikkei.com/Opinion/ASEAN-needs-smart-regulation-to-boost-financial-inclusion",
            "display_url": "asia.nikkei.com/Opinion/ASEAN-\u2026",
            "indices": [
              232,
              255
            ]
          }
        ]
      },
      "metadata": {
        "iso_language_code": "en",
        "result_type": "recent"
      },
      "source": "<a href=\"http://twitter.com/download/iphone\" rel=\"nofollow\">Twitter for iPhone</a>",
      "in_reply_to_status_id": null,
      "in_reply_to_status_id_str": null,
      "in_reply_to_user_id": null,
      "in_reply_to_user_id_str": null,
      "in_reply_to_screen_name": null,
      "user": {
        "id": 36032128,
        "id_str": "36032128",
        "name": "Nafis Alam",
        "screen_name": "nafisalam",
        "location": "Malaysia",
        "description": "#Fintech #Banking #AI & #Islamicfinance rsrchr, Prof. #Finance, Rsrch Afflt @CambridgeAltFin @CambridgeJBS, #RefinitivSocial100 Featured at @WEF @Huffington @FT",
        "url": "https://t.co/SHr1zruc54",
        "entities": {
          "url": {
            "urls": [
              {
                "url": "https://t.co/SHr1zruc54",
                "expanded_url": "https://www.jbs.cam.ac.uk/faculty-research/centres/alternative-finance/people/#item-2",
                "display_url": "jbs.cam.ac.uk/faculty-resear\u2026",
                "indices": [
                  0,
                  23
                ]
              }
            ]
          },
          "description": {
            "urls": []
          }
        },
        "protected": false,
        "followers_count": 1370,
        "friends_count": 359,
        "listed_count": 871,
        "created_at": "Tue Apr 28 10:07:40 +0000 2009",
        "favourites_count": 2790,
        "utc_offset": null,
        "time_zone": null,
        "geo_enabled": true,
        "verified": false,
        "statuses_count": 14264,
        "lang": null,
        "contributors_enabled": false,
        "is_translator": false,
        "is_translation_enabled": false,
        "profile_background_color": "8B542B",
        "profile_background_image_url": "http://abs.twimg.com/images/themes/theme8/bg.gif",
        "profile_background_image_url_https": "https://abs.twimg.com/images/themes/theme8/bg.gif",
        "profile_background_tile": false,
        "profile_image_url": "http://pbs.twimg.com/profile_images/1047679006651240450/6en7aJeA_normal.jpg",
        "profile_image_url_https": "https://pbs.twimg.com/profile_images/1047679006651240450/6en7aJeA_normal.jpg",
        "profile_banner_url": "https://pbs.twimg.com/profile_banners/36032128/1398224433",
        "profile_link_color": "9D582E",
        "profile_sidebar_border_color": "D9B17E",
        "profile_sidebar_fill_color": "EADEAA",
        "profile_text_color": "333333",
        "profile_use_background_image": true,
        "has_extended_profile": false,
        "default_profile": false,
        "default_profile_image": false,
        "following": false,
        "follow_request_sent": false,
        "notifications": false,
        "translator_type": "none"
      },
      "geo": null,
      "coordinates": null,
      "place": null,
      "contributors": null,
      "is_quote_status": false,
      "retweet_count": 0,
      "favorite_count": 0,
      "favorited": false,
      "retweeted": false,
      "possibly_sensitive": false,
      "lang": "en"
    },

In this simple result I'd to 'sum' for example how many tweets do I have in english.

"lang": "en"

I'm doing this:

>  db.last.aggregate([   {      $project: {           Total_english: { $sum: "$lang" },      }    }  ]);
{ "_id" : ObjectId("5e13c69578ad1c3e40f66675"), "Total_english" : 0 }

What am I doing wrong? Any help and light will be appreciate.

Thank you!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.