我正在尝试根据 Asya Kamsky 的帖子使用 MongoDB 和 Spring Data 实现自定义排序:
List<AggregationOperation> operations = new ArrayList<>();
operations.add(Aggregation.addFields().addField("scorrrz")
.withValueOfExpression("{ \"$indexOfArray\" : [ [\"John\", \"Bill\"], \"$name\" ] }").build());
Run Code Online (Sandbox Code Playgroud)
当我尝试执行此操作时,我得到:
ERROR a.insurance.misc.ErrorAttributes - /api/v1/insurance/opportunity/all
org.springframework.expression.spel.SpelParseException: Expression [{ "$indexOfArray" : [ ["John", "Bill"], "$name" ] }] @29: EL1043E: Unexpected token. Expected 'rsquare(])' but was 'comma(,)'
Run Code Online (Sandbox Code Playgroud)
这不是正确的语法吗?如何使用 Spring Data 来完成此操作?
mongodb spring-data aggregation-framework spring-data-mongodb
恐怕我的解决方案不是很有效:
fun String.mask() = if (isEmpty()) {
this
} else {
this[0] + String((1 until length).map { '*' }.toCharArray())
}
Run Code Online (Sandbox Code Playgroud)
你会怎么做?