I would like to select a set of ordered elements based on the number of elements in the array. Hopefully the following example will clarify my rather poor explanation:
class Thing
include MongoMapper::Document
key :name, String
key :tags, Array
end
I would like to get everything Thingordered from those who have more tags, with the smallest. The tags in this example are just strings in the tag array. Basically I want something that means the same thing as this (but works):
Thing.all(:order => 'tags.count desc')
Is it possible?
source
share