1

This is how my data looks like

{
        "_id" : "2011250546437843117",
        "name" : "Book",
       
        "textbook" : [
                "Maths",
                "Science"
],
       "language" : [
                "English"
        ],
         "isRead" : true,
        "isAvailable" : true
        
}

I have to filter documents based on textbook,and based on that isRead field should be true or false. my mongo query is


db.user.aggregate([
  {
    $match: {
          "isAvailable": true
    }
  },
  {
    $project: {
      
      "textbook": 1,
      "name": 1,
      "isread": {
        $in: [
          "Maths",
          "$textbook"
        ]
      }
    }
  }
]);

I have tried to write this using mongo-template

Aggregation aggregation = newAggregation(match(Criteria.where("isAvailable").is(true)),
project("textbook","name"));

I dont understand how to write the $in operator in project stage.

Thankyou in advance.

tini
  • 33
  • 4
  • 1
    similar question : https://stackoverflow.com/questions/59697496/how-to-do-a-mongo-aggregation-query-in-spring-data – R2D2 Jan 08 '21 at 23:42

0 Answers0