Individual key values ​​in the MongoDB sub-folder (100 million records)

I have 100 million entries in my sample collection. I want to have another collection with all the individual user names "user.screen_name"

I have the following structure in my collection of mododb samples:

{
"_id" : ObjectId("515af34297c2f607b822a54b"),
"text" : "random text goes here",
"user" :
  {
    "id" : 972863366,
    "screen_name" : "xname",
    "verified" : false,
    "time_zone" : "Amsterdam",
   }
}

When I try to do something like "distinct (user.id) .length", I get the following error:

    "errmsg" : "exception: distinct too big, 16mb cap",

I need an efficient way to have another collection with only {"user_name": "name"} different users in my collection "sample". so I can query the size of this new database and get the number of individual users. (and for further analysis in the future)

+1
1

, , :).. , - .

var SOURCE = db.sample;
var DEST = db.distinct;
DEST.drop();
map = function() {
  emit( this.user.screen_name , {count: 1});
}

reduce = function(key, values) {
  var count = 0;

  values.forEach(function(v) {
    count += v['count'];   
  });

  return {count: count};
};

res = SOURCE.mapReduce( map, reduce, 
    { out: 'distinct', 
     verbose: true
    }
    );

print( "distinct count= " + res.counts.output );
print( "distinct count=", DEST.count() );

0

All Articles