0

I am starting to use MongoDB and I have a problem in consultation with queries. The following error always happens.

db.user_tracking.distinct("q") Sun May 19 20:02:01.785 JavaScript execution failed: distinct failed: { "errmsg" : "exception: distinct too big, 16mb cap", "code" : 10044, "ok" : 0 } at src/mongo/shell/collection.js:L879

Can anyone tell me how to solve this? Thanks.

Andre Silva
  • 4,782
  • 9
  • 52
  • 65
Guandaline
  • 1
  • 1
  • 2
  • 4
    You probably need to look at this post=> http://stackoverflow.com/questions/11782566/mongodb-select-countdistinct-x-on-an-indexed-column-count-unique-results-for – origin1tech May 19 '13 at 23:22

1 Answers1

4

Well you are running into the 16MB document result in mongoDB When you call the distinct() method you will collect back an array of all distinct values for that given field. If such result is bigger than 16MB you'll get this error.

To avoid this you may want to use the aggregation framework where you can collect the same output but paginating the result ex:

db.user_tracking.aggregate( {$limit: X}, {$skip: Y}, {$group: {_id: "$q"} ) 

Loop around X and Y values and you overcome the 16MB limitation.

N.

Community
  • 1
  • 1
norberto
  • 187
  • 2
  • 3
    The pagination occurs before the group though. This means that as you paginate you will get duplicates. – Joe Jan 09 '14 at 14:16