sql >> Base de Datos >  >> NoSQL >> MongoDB

¿Spring Data MongoDb es compatible con el operador de agregaciones de arreglos $filter?

Puede solucionar este problema proporcionando su propio 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");