How to use to use pipeline within a $lookup in mongo aggregation in java

below is my $lookup code

{
  from: "profile_recommendation_info",
  localField: "_id",
  foreignField: "profile_id",
  as: "result",
  pipeline : [
    {
      $match : {
        "new_recommendations" : {
          $eq : null
        }
      }
    }
    ]
}

Below code is java equivalent code for lookup without in java

	LookupOperation lookupOperation  = Aggregation.lookup(CommonConstants.PROFILE_RECOMMENDATION_INFO, CommonConstants.ID, CommonConstants.PROFILE_UNDERSCORE_ID, CommonConstants.RESULT);

How to achieve the same in java but with pipeline condition in lookup(As shown in abovw $lookup aggregation query ) in java?

Hi @Sanjay_Naik,

My interpretation is that you’re after the Java equivalent of the $lookup you have provided. Please correct me if I am wrong here.

If that is the case, you may wish to try getting this using MongoDB Compass’s Export Pipeline to Specific Language feature.

Hope this helps.

Regards,
Jason

2 Likes