Search code examples
javamongodbmorphia

How can I sort MongoDB query results by inner array size?


I'm using Morphia to access mongoDB. I need to get a list of objects by the length of the inner array. Does any one have an idea how it can be done without getting all the collection to Java and sort it there?


Solution

  • OK I found it :-)

    dataStore.find(MyClass.class).order("-inner_array.length").asList();
    does the trick.