spring-projects / spring-data-mongodb

Provides support to increase developer productivity in Java when using MongoDB. Uses familiar Spring concepts such as a template classes for core API usage and lightweight repository style data access.
https://spring.io/projects/spring-data-mongodb/
Apache License 2.0
1.62k stars 1.09k forks source link

Why doesn't add field to Object in Aggregation addFields Operator? #4214

Closed lsb530 closed 2 years ago

lsb530 commented 2 years ago

AddFieldsOperation addFields = addFields() .addField("type").withValue("test").build();

mongoTemplate.aggregate To Object.class..

But It didn't added fields dynamically.. I know java is compiled language, if you can update added field to Object.

It works differently Mongo Compass pipeline

Thank you

christophstrobl commented 2 years ago

If you would like us to spend some time helping you to diagnose the problem, please spend some time describing it. Right now, we struggle to understand what you want to achieve.

lsb530 commented 2 years ago

Yes, I think It is quite impossible because Aggregation called by API so it it runtime. But Java is compile language. Can it be added new field to Object in Runtime?

You can test yourself make Aggregation Implements Aggregation.addFields() ... mongoTemplate.aggregate ...

When i make specific DTO class, It worked to DTO class. I expect that Object.class be added new field but it doesn't work

christophstrobl commented 2 years ago

I still struggle to understand what you want to achieve, please take the time to provide a complete minimal sample (something that we can unzip or git clone, build, and deploy) that reproduces the problem.

lsb530 commented 2 years ago

Okay..! Since i am in company.. Approximately 1 hour half, i will make it at home. Thank you

lsb530 commented 2 years ago

Sorry for that. Configuration change something which i don't know. At home, I tested Aggregation with AggregationResults ... It is working perfectly. Sorry for making confusion. I appreciate your effort for me. please close this fix question. Thank you

christophstrobl commented 2 years ago

Thanks for the feedback, glad it works for you now.