0

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 above $lookup aggregation query ) in java?

Sanjay Naik
  • 264
  • 1
  • 4
  • 23
  • Does this answer your question? [Spring Data MongoDB Lookup with Pipeline Aggregation](https://stackoverflow.com/questions/51107626/spring-data-mongodb-lookup-with-pipeline-aggregation) – Charchit Kapoor Sep 05 '22 at 06:50

1 Answers1

0

You can export aggregation stages to java among other languages from the aggregation section in mongo compass. Your lookup would be

Arrays.asList(new Document("$lookup", 
    new Document("from", "profile_recommendation_info")
            .append("localField", "_id")
            .append("foreignField", "profile_id")
            .append("as", "result")
            .append("pipeline", Arrays.asList(new Document("$match", 
                new Document("new_recommendations", 
                new Document("$eq", 
                new BsonNull())))))))
GameAtrix1
  • 370
  • 1
  • 3
  • 18