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

Closed
jmayday opened this issue Jun 11, 2024 · 4 comments
Closed

Aggregation pipeline breaks if $replaceRoot stage is present #4722

jmayday opened this issue Jun 11, 2024 · 4 comments
Assignees
Labels
type: bug A general bug

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
@moldo1997
Copy link

Hello,

Are there any updates regarding this issue?

Kind Regards,
Cristian

@nioe
Copy link

nioe commented Oct 7, 2024

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?

@mp911de mp911de added type: bug A general bug and removed status: feedback-provided Feedback has been provided labels Oct 8, 2024
@mp911de mp911de changed the title Aggregation pipeline breaks if $replaceRoot stage is present Aggregation pipeline breaks if $replaceRoot stage is present Oct 8, 2024
@mp911de mp911de added this to the 4.2.11 (2023.1.11) milestone Oct 8, 2024
@mp911de mp911de closed this as completed in 39e8f64 Oct 8, 2024
mp911de added a commit that referenced this issue Oct 8, 2024
See: #4722
Original pull request: #4723
mp911de pushed a commit that referenced this issue Oct 8, 2024
This change makes sure to apply conversion to non native mongo types when the context does not expose fields.

Closes: #4722
Original pull request: #4723
mp911de added a commit that referenced this issue Oct 8, 2024
See: #4722
Original pull request: #4723
mp911de pushed a commit that referenced this issue Oct 8, 2024
This change makes sure to apply conversion to non native mongo types when the context does not expose fields.

Closes: #4722
Original pull request: #4723
mp911de added a commit that referenced this issue Oct 8, 2024
See: #4722
Original pull request: #4723
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: bug A general bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants