spring-data-mongodb icon indicating copy to clipboard operation
spring-data-mongodb copied to clipboard

Need More Enhancement and Updation on SpEl - MethodReferenceNode.class

Open ganeshbabugb opened this issue 10 months ago • 2 comments

Hey Team, This is Ganesh. I feel that the available operations In SpEl - MethodReferenceNode work's fine but, In some operations like $trunc it doesn't works expected. when i give second argument it doesn't work well. Thank You.

ganeshbabugb avatar Jan 13 '25 19:01 ganeshbabugb

If you would like us to spend some time helping you to diagnose the problem, please spend some time describing it and, ideally, providing a minimal yet complete sample that reproduces the problem. You can share it with us by pushing it to a separate repository on GitHub or by zipping it up and attaching it to this issue.

mp911de avatar Jan 14 '25 08:01 mp911de

This is the simple example which help's you to reproduce this issue.

Ref: https://www.mongodb.com/docs/manual/reference/operator/aggregation/trunc/

@Component
@RequiredArgsConstructor
public class DemoService {
    private final MongoTemplate mongoTemplate;

    @EventListener({ApplicationStartedEvent.class})
    public void demoFunc() {
        // Initial Test Doc, Saved to DB Collection.
	//mongoTemplate.save(Map.of("test-key", 99.9999), "test-collection");

        // Actual Aggregation
        var matchCriteria = Aggregation.match(Criteria.where("_id").is("67864e50ea02266d41daadad")); // ObectId which i get from database after saving the inital doc.
        var projection = Aggregation.project().andExpression("trunc('$test-key')").as("result");
        var aggregation = Aggregation.newAggregation(matchCriteria, projection);
        mongoTemplate.aggregate(aggregation, "test-collection", Document.class);
    }
}

Agg Produced By This is :

[{ "$match" : { "_id" : { "$oid" : "67864e50ea02266d41daadad"}}}, { "$project" : { "result" : { "$trunc" : "$test-key"}}}]

But Actual Query What I expected when i replace expression like this is "trunc('$test-key', 1)" is

[
  {
    $match: {
      _id: ObjectId("67864e50ea02266d41daadad")
    }
  },
  {
    $project: {
      result: { $trunc: ["$test-key", 1] }
    }
  }
]

But it still producing the previous agg!.

ganeshbabugb avatar Jan 14 '25 12:01 ganeshbabugb