Description
I write a demo project to demostrate it. https://github.com/ArayChou/DBRefLookupTest . Please run unit test test.QueryTest to produce this issue.
@Document("person") public class PersonPo { @Id private String id; private String name; @DBRef private PersonPo mother; @DocumentReference private PersonPo father; }
AggregationOperation motherLookupDoesNotWork = Aggregation.lookup( "person", "mother.$id", "_id", "mother" );
The above $lookup operation does NOT work. it should work.
And I found a temporary solution, adding a (virtual) field to the document as following, it works.
AddFieldsOperation addMotherId = Aggregation.addFields().addField("motherId") .withValue("$mother.$id") .build(); AggregationOperation motherLookupWorks = Aggregation.lookup( "person", "motherId", "_id", "mother" );