When creating an aggregate query on MongoDB using Spring Data's ProjectionOperation class, using field with the "$" (for example 'test$') character causes an IllegalArgumentException
Verifying the spring data mongodb sources, I noticed that in the constructor of the AggregationField class a cleanup of the field name is performed. 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);
}
The nomenclature of the fields in MongoDB discourage the use of the "$" character or this is a Spring Data problem?
The reference documentation clearly states that it's currently not supported by the official MongoDB drivers:
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}
I.e. Spring Data cannot support that until support for that makes it into the official Java driver.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With