java - MongoDB distinct too big 16mb cap -
i have mongodb collection. simply, has 2 columns: user , url. has 39274590 rows. key of table {user, url}.
using java, try list distinct urls:
mongodbmanager db = new mongodbmanager( "website", "userlog" ); return db.getdistinct("url");
but receive exception:
exception in thread "main" com.mongodb.commandresult$commandfailure: command failed [distinct]: { "serverused" : "localhost/127.0.0.1:27017" , "errmsg" : "exception: distinct big, 16mb cap" , "code" : 10044 , "ok" : 0.0}
how can solve problem? there plan b can avoid problem?
thanks.
take @ answer
1) easiest way via aggregation framework. takes 2 "$group" commands: first 1 groups distinct values, second 1 counts of distinct values
2) if want map/reduce can. two-phase process: in first phase build new collection list of every distinct value key. in second count() on new collection.
note cannot return result of map/reduce inline, because potentially overrun 16mb document size limit. can save calculation in collection , count() size of collection, or can number of results return value of mapreduce().
Comments
Post a Comment