spring-data-mongodb
spring-data-mongodb copied to clipboard
Aggregation pipeline breaks if $replaceRoot stage is present
This is similar to already closed https://github.com/spring-projects/spring-data-mongodb/issues/4285.
If I include $replaceRoot stage, aggregation fails with CodecConfigurationException. Below is the (bit anonymized) aggregation itself. Workaround is to use $project instead of $replaceRoot (which is not that convenient).
org.bson.codecs.configuration.CodecConfigurationException: Can't find a codec for CodecCacheKey{clazz=class org.springframework.data.mongodb.core.aggregation.BooleanOperators$And, types=null}.
[
{
"$match": {
"$and": [
{
"fieldA": "some value"
}
]
}
},
{
"$sort": {
"updatedAt": -1
}
},
{
"$group": {
"_id": "$_some_field_id",
"latestRecord": {
"$first": "$$ROOT"
}
}
},
{
"$replaceRoot": {
"newRoot": "$latestRecord"
}
},
{
"$lookup": {
"from": "joinedCollectionName",
"let": {
"fieldB": "$fieldB",
"fieldA": "$fieldA",
"fieldC": "$fieldC"
},
"pipeline": [
{
"$match": {
"$expr": {
"$java": org.springframework.data.mongodb.core.aggregation.BooleanOperators$And@5d77efc8
}
}
}
],
"as": "myAlias"
}
}
]
Some dependency versions:
[INFO] +- org.springframework.boot:spring-boot-starter-data-mongodb:jar:3.3.0:compile
[INFO] | +- org.mongodb:mongodb-driver-sync:jar:5.0.1:compile
[INFO] | | +- org.mongodb:bson:jar:5.0.1:compile
[INFO] | | \- org.mongodb:mongodb-driver-core:jar:5.0.1:compile
[INFO] | | \- org.mongodb:bson-record-codec:jar:5.0.1:runtime
[INFO] | \- org.springframework.data:spring-data-mongodb:jar:4.3.0:compile
[INFO] | +- org.springframework:spring-tx:jar:6.1.8:compile
[INFO] | \- org.springframework.data:spring-data-commons:jar:3.3.0:compile
Do you happen to have a complete minimal sample (something that we can unzip or git clone, build, and deploy) that reproduces the problem? Also the java representation of the pipeline as well as execution paths & stack traces would be a good thing to add. Thank you!
@christophstrobl please check @banhidizoli's example from here https://github.com/spring-projects/spring-data-mongodb/issues/4285
I manage to reproduce it on 4.2.5 version.
Hello,
Are there any updates regarding this issue?
Kind Regards, Cristian
I'm running into the same issue. The produced error is really misleading. It took me a while to stumble upon this Issue. Any plans when the PR gets merged?