如何按内部数组大小对MongoDB查询结果进行排序? [英] How can I sort MongoDB query results by inner array size?

查看:179
本文介绍了如何按内部数组大小对MongoDB查询结果进行排序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Morphia来访问mongoDB。
我需要按内部数组的长度获取对象列表。
是否有人知道如何在不将所有集合转换为Java并将其排序的情况下完成它?

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?

推荐答案

好的我找到了: - )

OK I found it :-)

dataStore.find(MyClass.class).order( - inner_array.length)。asList ();
$
可以解决问题。

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

这篇关于如何按内部数组大小对MongoDB查询结果进行排序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆