I am writing a mapreduce function and the following is what I have right now:

function myMapper() { //The mapper function is called with each document, which has the special name 'this' //Emit a key-value pair: var hashtag; for (hashtag in this.entities.hashtags) { //print(hashtag.text); emit(hashtag.text, 1); } //emit(this.entities, 1); } function myReducer(key, values) { //The reducer is called once for each key, and is passed an array //containing all values corresponding to that key. //Produce the desired result return Array.sum( values ); } db.tweets.mapReduce(myMapper, myReducer, { query: {}, out: "hashtags" }) db.hashtags.aggregate({$sort: {value: -1}})

I am seeing a null output from this mapreduce as seen below:

{ "_id" : null, "value" : 454540 }

I know that entities is a field, then hashtags is an array, right? So why is this code not working?

{ "_id" : ObjectId("5aa58befc4214f42f4c7cc70"), "created_at" : "Mon Apr 24 14:39:49 +0000 2017", "id" : NumberLong("856518043605905409"), "id_str" : "856518043605905409", "text" : "RT @Sheena_Davis: Lots of activities for Safety week

May 1-6 dfghdfghd #SafeCityLondon #ldnont", "source" : "<a href=\"bnmvnm" rel=\"nofollow\">Twitter Web Client</a>", "truncated" : false, "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" : 83649318, "id_str" : "83649318", "name" : "MLHealthUnit", "screen_name" : "MLHealthUnit", "location" : "London and Middlesex County", "description" : "Official account of the Middlesex-London Health Unit │We promote and protect the health of our community. We’re HERE for YOU. #MLHU #LdnOnt", "protected" : false, "verified" : true, "followers_count" : 9937, "friends_count" : 3794, "listed_count" : 257, "favourites_count" : 6287, "profile_link_color" : "008265", "default_profile" : false, "default_profile_image" : false, "following" : null, "follow_request_sent" : null, "notifications" : null }, "geo" : null, "coordinates" : null, "place" : null, "contributors" : null, "retweeted_status" : { "created_at" : "Mon Apr 24 10:24:21 +0000 2017", "id" : NumberLong("856453750915043328"), "id_str" : "856453750915043328", "text" : "Lots of activities for Safety week

May 1-6 ghjghj #SafeCityLondon #ldnont", "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" : 144868126, "id_str" : "144868126", "name" : "Sheena Davis", "screen_name" : "Sheena_Davis", "location" : "London ON CA", }, "entities" : { "hashtags" : [ { "text" : "SafeCityLondon", "indices" : [ 68, 83 ] }, { "text" : "ldnont", "indices" : [ 84, 91 ] } ], "urls" : [ { "url" : "dfgdf.co", "expanded_url" : "url.ckdkd", "display_url" : "ghjghj", "indices" : [ 44, 67 ] } ], "user_mentions" : [ ], "symbols" : [ ] }, "favorited" : false, "retweeted" : false, "possibly_sensitive" : false, "filter_level" : "low", "lang" : "en" } }

I am not the most experienced with javascript but it's quite limited in terms of troubleshooting mapreduce it seems.

Update: I feel like I tried everything at this point. Honestly, it has to be the mapper code but I am not sure what it is.

Here is some of the 'debugging' I have been doing: