micronaut-data icon indicating copy to clipboard operation
micronaut-data copied to clipboard

Join Annotation Does Not Change MongoDB Query

Open SenorPez opened this issue 1 year ago • 1 comments

Expected Behavior

By default, a find query should be generated by the repository interface. According to the documentation (https://micronaut-projects.github.io/micronaut-data/latest/guide/#mongoJoinQueries), using the Join annotation switches to the aggregation pipeline to populate relationship fields.

Actual Behaviour

It doesn't.

@MongoRepository
public interface StarSystemRepository extends CrudRepository<StarSystem, Integer> {
}

and

@MongoRepository
public interface StarSystemRepository extends CrudRepository<StarSystem, Integer> {
    @Override
    @Join("stars")
    @NonNull List<StarSystem> findAll();
}

generates an identical find query.

{"find": "starSystems", "filter": {"_id": {"$eq": 867158537}}, "limit": 1, "singleBatch": true, "$db": "pezdb", "lsid": {"id": {"$binary": {"base64": "qKkxNgeFTdi4SwSSwNvnHA==", "subType": "04"}}}}

The aggregation pipeline is never called, so objects are never populated. Placing the Join annotation in other places (under the Relationship, creating a non-Override interface method, etc.) also never stop the generation of that same find query. The related object is never populated.

Steps To Reproduce

No response

Environment Information

No response

Example Application

No response

Version

4.4.4

SenorPez avatar Jan 01 '25 04:01 SenorPez

This is supposed to work, we have number of tests with joined entities in MongoDB. Here is attached example app with test with joined entity mn-mongo-join.zip

Please take a look and maybe create reproducer with your example.

radovanradic avatar Jan 31 '25 13:01 radovanradic