Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Aggregation pipeline breaks if $replaceRoot stage is present #4722

Open
jmayday opened this issue Jun 11, 2024 · 2 comments · May be fixed by #4723
Open

Aggregation pipeline breaks if $replaceRoot stage is present #4722

jmayday opened this issue Jun 11, 2024 · 2 comments · May be fixed by #4723
Labels
status: feedback-provided Feedback has been provided

Comments

@jmayday
Copy link

jmayday commented Jun 11, 2024

This is similar to already closed #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
@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Jun 11, 2024
@christophstrobl
Copy link
Member

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 christophstrobl added status: waiting-for-feedback We need additional information before we can continue and removed status: waiting-for-triage An issue we've not yet triaged labels Jun 12, 2024
@pbeltechi
Copy link

pbeltechi commented Jun 12, 2024

@christophstrobl please check @banhidizoli's example from here #4285

I manage to reproduce it on 4.2.5 version.

@spring-projects-issues spring-projects-issues added status: feedback-provided Feedback has been provided and removed status: waiting-for-feedback We need additional information before we can continue labels Jun 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: feedback-provided Feedback has been provided
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants