-
Type: Task
-
Resolution: Done
-
Affects Version/s: None
-
Component/s: None
-
Labels:None
Sometimes we want to get a distinct count of fields, but not the distinct values themselves. So we do Comment.distinct(:author_id).size. This works, but requires loading the whole array of author_ids into memory first which doesn't scale quite as well.
I was curious if there was a convenient way to do this all in the db.
It seems doable with a custom aggregation or map reduce, where you do the .size in the reduce step. or pipeline. But I was just curious if Mongoid had an easier built in way to do this. Thanks!