小编jjr*_*jrz的帖子

Spring Data 中的 MongoDB $addField 和 $indexOfArray

我正在尝试根据 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

2
推荐指数
1
解决办法
2791
查看次数

在 Kotlin 中屏蔽除第一个字符之外的所有字符

恐怕我的解决方案不是很有效:

fun String.mask() = if (isEmpty()) {
    this
} else {
    this[0] + String((1 until length).map { '*' }.toCharArray())
}
Run Code Online (Sandbox Code Playgroud)

你会怎么做?

kotlin

1
推荐指数
1
解决办法
1930
查看次数