ruby - Order items in MongoDB according to the size of an array with MongoMapper? -


I want to select a collection of sorted items based on the number of items within an array. Hopefully, in the following example, the poor interpretation will be clear instead of me:

  In the class Thing in Mongomar :: Document key: name, string key: tag, array and  
< P> I want to get all the things that get the order from the people with the most tags from all those people, at least in this example the tags are only the wire within the tag array. I need something that means it The following works):

  Thing.all (: order = & gt; 'tags.count desc')  

Is it possible?

The main server does not currently support the computing of an array size and then it is sorted by me It seems that for the moment your best bet is to cache all shapes on your own, and add an index to that area.

  The things in the class include MongoMapper :: Document key: name, string key: tag, array key: tag_size, integer,: default = & gt; 0,: index = & gt;  

Just add a callback to your model which updates Tag_yize on savings.

If this is a feature you want to see in the core server, you can add a case here:


Comments

Popular posts from this blog

oracle - The fastest way to check if some records in a database table? -

php - multilevel menu with multilevel array -

jQuery UI: Datepicker month format -