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

MongoDB Comando di aggregazione al codice Java

asList("$modifiedon",1000) dovrebbe essere asList("$modifiedon","$createdon") secondo la pipeline di lavoro da te fornita.

Come hai fatto la modifica. Vedo che il problema è che stai aggiungendo "then" e "else" al documento "$gt" anziché "if".

Quindi invece di:

AggregateIterable<Document> iterable = collection.aggregate(

asList( new Document("$redact", 
         new Document("$cond", 
             new Document("if", 
                 new Document("$gt",
                      asList(new Document("$subtract",
                          asList("$modifiedon", "$createdon")
                      ),1000 * 60 * 60 * 24)
              ).append("then", "$$KEEP")
               .append("else", "$$PRUNE")
             )
         )
     )
)); 

Dovresti fare :

AggregateIterable<Document> iterable = collection.aggregate(

asList( new Document("$redact", 
         new Document("$cond", 
             new Document("if", 
                 new Document("$gt",
                      asList(new Document("$subtract",
                          asList("$modifiedon", "$createdon")
                      ),1000 * 60 * 60 * 24)
              )
             ).append("then", "$$KEEP")
               .append("else", "$$PRUNE")
         )
     )
));