Frequency (histogram) was a topic covered in chapter 5. I examined the frequency of stars field by bucketing it to find out whether it’s monotonically increasing using the following aggregate query:
I got " Sort exceeded memory limit of 104857600 bytes", however, an index on stars exists. if stars > 2 or so, no error is issued. How is such problem solved? Also, is there another way of getting a histogram of all fields or specified fields beside $facet?
I think that you’re hitting the memory limit for $bucketAuto. See MongoDB documentation:
“The $bucketAuto stage has a limit of 100 megabytes of RAM. By default, if the stage exceeds this limit, $bucketAuto returns an error. To allow more space for stage processing, use the use the allowDiskUse option to enable aggregation pipeline stages to write data to temporary files.”