asList("$modifiedon",1000)
phải là asList("$modifiedon","$createdon")
theo quy trình hoạt động do bạn cung cấp.
Khi bạn đã thực hiện chỉnh sửa. Có thể thấy rằng vấn đề là bạn đang thêm "then" và "else" vào tài liệu "$ gt" thay vì "if".
Vì vậy, thay vì:
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")
)
)
)
));
Bạn nên làm:
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")
)
)
));