MongoDB
 sql >> Database >  >> NoSQL >> MongoDB

Spring Data MongoDb supporta l'operatore di aggregazioni di array $filter?

Puoi risolvere questo problema fornendo il tuo AggregationExpression .

ProjectionOperation agg = Aggregation.project() //

      .and(new AggregationExpression() {

        @Override
        public DBObject toDbObject(AggregationOperationContext context) {

          DBObject filterExpression = new BasicDBObject();
          filterExpression.put("input", "$answer_list");
          filterExpression.put("as", "answer");
          filterExpression.put("cond", new BasicDBObject("$eq2", Arrays.<Object> asList("$$answer.question", 2)));

          return new BasicDBObject("$filter", filterExpression);
        }
      }).as("profile");