我通过MongoDB ( Java )使用Jongo,我需要对特定查询以不区分大小写的方式对结果进行排序。
MongoDB文件指出,应该使用一定的排序规则级别创建索引,并且查询应该使用相同的配置:
db.fruit.find( {type: "apple"} )
.collation( {locale: 'en', strength: 2} )创建索引很容易;但我无法找到使用Jongo的query传递排序规则配置的位置。
Find query = myCollection.find(match); // No .collation() method here知道吗?
发布于 2018-04-03 09:46:23
使用一个查询修饰符,它可以通过实现DBCursor在QueryModifier上设置,并将其传递给'with‘方法:
friends.find().with(new QueryModifier() {
public void modify(DBCursor cursor) {
cursor.setCollation(
Collation.builder().collationStrength(CollationStrength.SECONDARY).
locale("en").
build())
}
}).as(Friend.class);https://stackoverflow.com/questions/41999083
复制相似问题