Skip to content

@Field annotation not honoured after $unwind stage in aggregation #4443

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

Closed
scrum-futch opened this issue Jul 10, 2023 · 3 comments
Closed

@Field annotation not honoured after $unwind stage in aggregation #4443

scrum-futch opened this issue Jul 10, 2023 · 3 comments
Assignees
Labels
type: bug A general bug

Comments

@scrum-futch
Copy link

Hi I have following pojos :

package model;

import lombok.Data;
import org.springframework.data.annotation.Id;
import org.springframework.data.mongodb.core.mapping.Document;
import org.springframework.data.mongodb.core.mapping.Field;

import java.util.List;

@Document(collection = "pojo")
@Data
public class Pojo {

    @Id
    String id;

    List<PojoLine> lines;

    @Field("pojo_header")
    PojoHeader header;

    Integer total;
}
 
package model;

import lombok.Data;

@Data
public class PojoHeader {

    String name;

    Integer amount;

}
 
package model;

import lombok.Data;

@Data
public class PojoLine {

    String status;

    String description;

}

Document in my db is :

{

    "_id" : "1",

    "lines" : [

        {

            "status" : "Created",

            "description" : "Create"

        },

        {

            "status" : "Deleted",

            "description" : "Delete"

        }

    ],

    "pojo_header" : {

        "name" : "Test",

        "amount" : NumberInt(1)

    },

    "total" : NumberInt(1)

}

My aggregation query is :

List<AggregationOperation> pipeline = Arrays.asList(
        Aggregation.match(new Criteria("lines.status").is("Deleted")
                .and("header.name").is("Test")),
        Aggregation.unwind("$lines"),
        Aggregation.match(new Criteria("lines.status").is("Deleted")
                .and("header.name").is("Test"))
);
TypedAggregation<Pojo> aggregation = Aggregation.newAggregation(Pojo.class, pipeline);

Ideally, I should get back one document. But I don't get any output.

Upon debugging I found the aggregation query internally is :

[{

    "$match": {

        "lines.status": "Delete",

        "pojo_header.name": "Test"

    }

}, {

    "$unwind": "$lines"

}, {

    "$match": {

        "lines.status": "Delete",

        "header.name": "Test"

    }

}]

Here in the first match stage, I have the correct fieldName as per @field annotation i.e. pojo_header.name

but in the stage after unwind it's header.name instead of pojo_header.name

Test code to showcase issue is present in: https://github.com/scrum-futch/Aggregation-issue

Test code that was previous working before updating here: https://github.com/scrum-futch/Aggregation-issue/tree/Previously_working

aggregation pipeline is logged after log "----Check the pipeline log after this-----"

Please share if there is any workaround for the same.

MongoDB: 4.4

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Jul 10, 2023
@sxhinzvc sxhinzvc added type: bug A general bug and removed status: waiting-for-triage An issue we've not yet triaged labels Jul 25, 2023
@scrum-futch
Copy link
Author

Which version would contain the fix?

sxhinzvc added a commit that referenced this issue Jul 26, 2023
…on pipelines.

Use the root AggregationOperationContext in nested ExposedFieldsAggregationOperationContext to properly apply mapping for domain properties that use @field.

Closes #4443
sxhinzvc added a commit that referenced this issue Jul 26, 2023
…on pipelines.

Use the root AggregationOperationContext in nested ExposedFieldsAggregationOperationContext to properly apply mapping for domain properties that use @field.

Closes #4443
@sxhinzvc
Copy link
Contributor

Thanks for reporting, @scrum-futch. Not sure exactly which version, but there's a PR in progress.

christophstrobl pushed a commit that referenced this issue Jul 27, 2023
…on pipelines.

Use the root AggregationOperationContext in nested ExposedFieldsAggregationOperationContext to properly apply mapping for domain properties that use @field.

Closes #4443
christophstrobl pushed a commit that referenced this issue Jul 28, 2023
…on pipelines.

Use the root AggregationOperationContext in nested ExposedFieldsAggregationOperationContext to properly apply mapping for domain properties that use @field.

Closes #4443
Original Pull Request: #4459
christophstrobl pushed a commit that referenced this issue Jul 28, 2023
…on pipelines.

Use the root AggregationOperationContext in nested ExposedFieldsAggregationOperationContext to properly apply mapping for domain properties that use @field.

Closes #4443
Original Pull Request: #4459
christophstrobl pushed a commit that referenced this issue Jul 28, 2023
…on pipelines.

Use the root AggregationOperationContext in nested ExposedFieldsAggregationOperationContext to properly apply mapping for domain properties that use @field.

Closes #4443
Original Pull Request: #4459
@christophstrobl christophstrobl added this to the 3.4.15 (2021.2.15) milestone Jul 28, 2023
@scrum-futch
Copy link
Author

When is the estimated release date for 3.4.15?

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
4 participants