Mongodb $lookup in Spring data mongo

后端 未结 5 1903
走了就别回头了
走了就别回头了 2020-12-31 12:32

I\'m a new Mongodb and I have a problem with $lookup with java spring.

I would like to use this shell in Spring data

db.NewFeed.aggregate([
    {
           


        
5条回答
  •  滥情空心
    2020-12-31 13:01

    Its too late to answer this, but it might helps other who are facing the same issue. If you are using spring-boot-data-mongodb-2.0 or above version then there is a easy way to implement this.

    AggregationOperation match = Aggregation.match(Criteria.where("username").is("user001")));
    AggregationOperation query = Aggregation.lookup("NewfeedContent", "content.contentId", "_id", "NewfeedContent");
    // If you want to unwind
    //AggregationOperation unwind = Aggregation.unwind("Patient");
    Aggregation agr = Aggregation.newAggregation(query, match, unwind);
    AggregationResults result = springTemplate.aggregate(agr, "CollectionName", Document.class);
    

提交回复
热议问题