java-为什么Spring Data MongoDB在聚合管道中拒绝包含$的字段名?

使用Spring Data的ProjectionOperation类在MongoDB上创建聚合查询时,使用带有“ $”(例如’test $’)字符的字段会导致IllegalArgumentException

 

验证spring数据mongodb源时,我注意到在AggregationField类的构造函数中,对字段名称进行了清理. Fields.java Class

 

private static String cleanUp(String source) {

    if (Aggregation.SystemVariable.isReferingToSystemVariable(source)) {
        return source;
    }

    int dollarIndex = source.lastIndexOf('$');
    return dollarIndex == -1 ? source : source.substring(dollarIndex + 1);
}

MongoDB中字段的命名法不鼓励使用“ $”字符,否则这是Spring Data问题吗?

最佳答案

MongoDB官方驱动程序当前不支持的reference documentation clearly states

 

 

IMPORTANT

The MongoDB Query Language cannot always meaningfully express queries over documents whose field names contain these characters (see SERVER-30575). Until support is added in the query language, the use of $and . in field names is not recommended and is not supported by the official MongoDB drivers.
{quote}

即Spring Data无法支持该功能,除非对此提供支持,以使其成为正式的Java驱动程序.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值