@Override
    public long countTicketsFor(final Service service) {
        return ticketCatalog
            .findAll()
            .stream()
            .map(this::getTicketCollectionInstanceByMetadata)
            .flatMap(map -> {
                val query = new Query(Criteria.where(MongoDbTicketDocument.FIELD_NAME_SERVICE).is(service.getId()));
                return mongoTemplate.stream(query, MongoDbTicketDocument.class, map);
            })
            .map(document -> {
                val ticket = decodeTicket(deserializeTicket(document.getJson(), document.getType()));
                return ticket != null ? !ticket.isExpired() : null;
            })
            .filter(Objects::nonNull)
            .count();
    }
Calculate the time at which the ticket is eligible for automated deletion by MongoDb.
Makes the assumption that the CAS server date and the Mongo server date are in sync.
support/cas-server-support-mongo-ticket-registry/src/main/java/org/apereo/cas/ticket/registry/MongoDbTicketRegistry.java