Example usage for com.mongodb.client.model Accumulators max

List of usage examples for com.mongodb.client.model Accumulators max

Introduction

In this page you can find the example usage for com.mongodb.client.model Accumulators max.

Prototype

public static <TExpression> BsonField max(final String fieldName, final TExpression expression) 

Source Link

Document

Gets a field name for a $group operation representing the maximum of the values of the given expression when applied to all members of the group.

Usage

From source file:com.epam.dlab.backendapi.dao.azure.AzureBillingDAO.java

License:Apache License

private Bson groupCriteria() {
    return Aggregates.group(
            getGroupingFields(MongoKeyWords.DLAB_USER, MongoKeyWords.DLAB_ID, MongoKeyWords.RESOURCE_TYPE,
                    MongoKeyWords.METER_CATEGORY, MongoKeyWords.CURRENCY_CODE),
            Accumulators.sum(MongoKeyWords.COST, MongoKeyWords.prepend$(MongoKeyWords.COST)),
            Accumulators.min(MongoKeyWords.USAGE_FROM, MongoKeyWords.prepend$(MongoKeyWords.USAGE_DAY)),
            Accumulators.max(MongoKeyWords.USAGE_TO, MongoKeyWords.prepend$(MongoKeyWords.USAGE_DAY)));
}

From source file:com.epam.dlab.billing.azure.AzureBillingDetailsService.java

License:Apache License

public void updateBillingDetails(String user) {
    log.debug("Updating billing details for user {}", user);

    try {//from   w  w  w . j a  va 2 s . c o m
        AggregateIterable<Document> aggregateIterable = mongoDbBillingClient.getDatabase()
                .getCollection(MongoKeyWords.BILLING_DETAILS)
                .aggregate(Lists.newArrayList(
                        Aggregates.match(Filters.and(Filters.eq(MongoKeyWords.DLAB_USER, user),
                                Filters.in(MongoKeyWords.RESOURCE_TYPE, DlabResourceType.EXPLORATORY.toString(),
                                        DlabResourceType.COMPUTATIONAL.toString(),
                                        DlabResourceType.VOLUME.toString()))),

                        Aggregates.group(
                                getGroupingFields(MongoKeyWords.DLAB_ID, MongoKeyWords.DLAB_USER,
                                        MongoKeyWords.EXPLORATORY_ID, MongoKeyWords.RESOURCE_TYPE,
                                        MongoKeyWords.RESOURCE_NAME, MongoKeyWords.COMPUTATIONAL_ID,
                                        MongoKeyWords.METER_CATEGORY),
                                Accumulators.sum(MongoKeyWords.COST,
                                        MongoKeyWords.prepend$(MongoKeyWords.COST)),
                                Accumulators.min(MongoKeyWords.USAGE_FROM,
                                        MongoKeyWords.prepend$(MongoKeyWords.USAGE_DAY)),
                                Accumulators.max(MongoKeyWords.USAGE_TO,
                                        MongoKeyWords.prepend$(MongoKeyWords.USAGE_DAY))),

                        Aggregates.sort(Sorts.ascending(MongoKeyWords.prependId(MongoKeyWords.RESOURCE_NAME),
                                MongoKeyWords.prependId(MongoKeyWords.METER_CATEGORY)))));

        updateBillingDetails(user, mapToDetails(aggregateIterable));
    } catch (RuntimeException e) {
        log.error("Updating billing details for user {} is failed", user, e);
    }
}