• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java Accumulators类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中com.mongodb.client.model.Accumulators的典型用法代码示例。如果您正苦于以下问题:Java Accumulators类的具体用法?Java Accumulators怎么用?Java Accumulators使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



Accumulators类属于com.mongodb.client.model包,在下文中一共展示了Accumulators类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: averageAge

import com.mongodb.client.model.Accumulators; //导入依赖的package包/类
@Test
public void averageAge() {
    AggregateIterable<Document> documents
            = userDocuments.aggregate(
                    Arrays.asList(
                            Aggregates.group("$company",
                                    Accumulators.avg("averageAge", "$age")),
                            Aggregates.sort(Sorts.ascending("_id"))
                    ));
    List<Document> docs = intoList(documents);
    assertEquals("Should be three companies", 3, docs.size());

    assertEquals("Frogs, Inc.", docs.get(0).get("_id"));
    assertEquals(37.0, docs.get(0).get("averageAge"));
    assertEquals("IBM", docs.get(1).get("_id"));
    assertEquals(37.0, docs.get(1).get("averageAge"));
    assertEquals("UMM", docs.get(2).get("_id"));
    assertEquals(25.0, docs.get(2).get("averageAge"));
}
 
开发者ID:UMM-CSci-3601-S17,项目名称:digital-display-garden-iteration-2-spraguesanborn,代码行数:20,代码来源:MongoSpec.java


示例2: returnValueToURL

import com.mongodb.client.model.Accumulators; //导入依赖的package包/类
public int returnValueToURL(String URL)
{
    Block<Document> printBlock = new Block<Document>() {
        @Override
        public void apply(final Document document) {
            System.out.println(document.toJson());
        }
    };
    MongoCollection<Document> collection = db.getCollection("ratings");

    collection.aggregate(
            Arrays.asList(
                    Aggregates.group("URL", Accumulators.avg("rating", 1))))
            .forEach(printBlock);
    System.out.println(printBlock.toString());
    return 0;
}
 
开发者ID:Sigma-News,项目名称:Backend,代码行数:18,代码来源:MongoDBManager.java


示例3: ageCounts

import com.mongodb.client.model.Accumulators; //导入依赖的package包/类
@Test
public void ageCounts() {
    AggregateIterable<Document> documents
            = userDocuments.aggregate(
            Arrays.asList(
                    /*
                     * Groups data by the "age" field, and then counts
                     * the number of documents with each given age.
                     * This creates a new "constructed document" that
                     * has "age" as it's "_id", and the count as the
                     * "ageCount" field.
                     */
                    Aggregates.group("$age",
                            Accumulators.sum("ageCount", 1)),
                    Aggregates.sort(Sorts.ascending("_id"))
            )
    );
    List<Document> docs = intoList(documents);
    assertEquals("Should be two distinct ages", 2, docs.size());
    assertEquals(docs.get(0).get("_id"), 25);
    assertEquals(docs.get(0).get("ageCount"), 1);
    assertEquals(docs.get(1).get("_id"), 37);
    assertEquals(docs.get(1).get("ageCount"), 2);
}
 
开发者ID:UMM-CSci-3601-S17,项目名称:digital-display-garden-iteration-3-sixguysburgers-fries,代码行数:25,代码来源:MongoSpec.java


示例4: max

import com.mongodb.client.model.Accumulators; //导入依赖的package包/类
/**
 * 最大统计
 *
 * @param collectionName
 * @param match
 * @param maxField
 * @return
 */
public Object max(String collectionName, Document match, String maxField) {
    AggregateIterable<Document> aggregate = getDB().getCollection(collectionName).aggregate(
            Arrays.asList(
                    match(match)
                    , group(null, Accumulators.max("_max", "$" + maxField))
            )
    );
    Document first = aggregate.first();
    if (first != null) {
        return first.get("_max");
    }
    return null;
}
 
开发者ID:ysrc,项目名称:Liudao,代码行数:22,代码来源:MongoDao.java


示例5: sortMap

import com.mongodb.client.model.Accumulators; //导入依赖的package包/类
/**
 * 根据统计字段计算统计结果(gte最小值)并排序
 *
 * @param collectionName 集合名
 * @param match          match条件
 * @param field          统计字段
 * @param minCount       最小值
 * @return
 */
public LinkedHashMap<String, Integer> sortMap(String collectionName, Document match, String field, int minCount) {
    AggregateIterable<Document> aggregate = getDB().getCollection(collectionName).aggregate(
            Arrays.asList(
                    match(match)
                    , group("$" + field, Accumulators.sum("_count", 1))
                    , match(new Document("_count", new Document("$gte", minCount)))
                    , sort(new Document("_count", -1))
            )
    );

    LinkedHashMap<String, Integer> map = new LinkedHashMap<String, Integer>();
    MongoCursor<Document> iterator = aggregate.iterator();
    while (iterator.hasNext()) {
        Document next = iterator.next();
        map.put(next.getString("_id"), next.getInteger("_count"));
    }
    return map;
}
 
开发者ID:ysrc,项目名称:Liudao,代码行数:28,代码来源:MongoDao.java


示例6: getAverageAgeByCompany

import com.mongodb.client.model.Accumulators; //导入依赖的package包/类
public String getAverageAgeByCompany() {
    AggregateIterable<Document> documents
            = userCollection.aggregate(
            Arrays.asList(
                    Aggregates.group("$company",
                            Accumulators.avg("averageAge", "$age")),
                    Aggregates.sort(Sorts.ascending("_id"))
            ));
    System.err.println(JSON.serialize(documents));
    return JSON.serialize(documents);
}
 
开发者ID:UMM-CSci-3601-S17,项目名称:digital-display-garden-iteration-2-spraguesanborn,代码行数:12,代码来源:UserController.java


示例7: min

import com.mongodb.client.model.Accumulators; //导入依赖的package包/类
/**
 * 最小统计
 *
 * @param collectionName
 * @param match
 * @param minField
 * @return
 */
public Object min(String collectionName, Document match, String minField) {
    AggregateIterable<Document> aggregate = getDB().getCollection(collectionName).aggregate(
            Arrays.asList(
                    match(match)
                    , group(null, Accumulators.min("_min", "$" + minField))
            )
    );
    Document first = aggregate.first();
    if (first != null) {
        return first.get("_min");
    }
    return null;
}
 
开发者ID:ysrc,项目名称:Liudao,代码行数:22,代码来源:MongoDao.java


示例8: sum

import com.mongodb.client.model.Accumulators; //导入依赖的package包/类
/**
 * 合统计
 *
 * @param collectionName
 * @param match
 * @param sumField
 * @return
 */
public Double sum(String collectionName, Document match, String sumField) {
    AggregateIterable<Document> aggregate = getDB().getCollection(collectionName).aggregate(
            Arrays.asList(
                    match(match)
                    , group(null, Accumulators.sum("_sum", "$" + sumField))
            )
    );
    Document first = aggregate.first();
    if (first != null) {
        return first.getDouble("_sum");
    }
    return null;
}
 
开发者ID:ysrc,项目名称:Liudao,代码行数:22,代码来源:MongoDao.java


示例9: avg

import com.mongodb.client.model.Accumulators; //导入依赖的package包/类
/**
 * 平均统计
 *
 * @param collectionName
 * @param match
 * @param avgField
 * @return
 */
public Double avg(String collectionName, Document match, String avgField) {
    AggregateIterable<Document> aggregate = getDB().getCollection(collectionName).aggregate(
            Arrays.asList(
                    match(match)
                    , group(null, Accumulators.avg("_avg", "$" + avgField))
            )
    );
    Document first = aggregate.first();
    if (first != null) {
        return first.getDouble("_avg");
    }
    return null;
}
 
开发者ID:ysrc,项目名称:Liudao,代码行数:22,代码来源:MongoDao.java


示例10: last

import com.mongodb.client.model.Accumulators; //导入依赖的package包/类
/**
 * 最近统计
 *
 * @param collectionName
 * @param match
 * @param lastField
 * @param sort
 * @return
 */
public Object last(String collectionName, Document match, String lastField, Document sort) {
    AggregateIterable<Document> aggregate = getDB().getCollection(collectionName).aggregate(
            Arrays.asList(
                    match(match)
                    , sort(sort)
                    , group(null, Accumulators.last("_last", "$" + lastField))
            )
    );
    Document first = aggregate.first();
    if (first != null) {
        return first.get("_last");
    }
    return null;
}
 
开发者ID:ysrc,项目名称:Liudao,代码行数:24,代码来源:MongoDao.java


示例11: stdDevPop

import com.mongodb.client.model.Accumulators; //导入依赖的package包/类
/**
 * 标准差统计
 *
 * @param collectionName
 * @param match
 * @param stdDevField
 * @return
 */
public Double stdDevPop(String collectionName, Document match, String stdDevField) {
    AggregateIterable<Document> aggregate = getDB().getCollection(collectionName).aggregate(
            Arrays.asList(
                    match(match)
                    , group(null, Accumulators.stdDevPop("_stdDev", "$" + stdDevField))
            )
    );
    Document first = aggregate.first();
    if (first != null) {
        return first.getDouble("_stdDev");
    }
    return null;
}
 
开发者ID:ysrc,项目名称:Liudao,代码行数:22,代码来源:MongoDao.java


示例12: stdDevSamp

import com.mongodb.client.model.Accumulators; //导入依赖的package包/类
/**
 * 采样标准差统计
 *
 * @param collectionName
 * @param match
 * @param stdDevField
 * @param sampleSize
 * @return
 */
public Double stdDevSamp(String collectionName, Document match, String stdDevField, int sampleSize) {
    AggregateIterable<Document> aggregate = getDB().getCollection(collectionName).aggregate(
            Arrays.asList(
                    match(match)
                    , sample(sampleSize)
                    , group(null, Accumulators.stdDevSamp("_stdDev", "$" + stdDevField))
            )
    );
    Document first = aggregate.first();
    if (first != null) {
        return first.getDouble("_stdDev");
    }
    return null;
}
 
开发者ID:ysrc,项目名称:Liudao,代码行数:24,代码来源:MongoDao.java


示例13: inSortMap

import com.mongodb.client.model.Accumulators; //导入依赖的package包/类
/**
 * 统计值 是否在统计结果(gte最小值)中
 *
 * @param collectionName 集合名
 * @param match          match条件
 * @param field          统计字段
 * @param value          统计值
 * @param minCount       最小值
 * @return
 */
public boolean inSortMap(String collectionName, Document match, String field, Object value, int minCount) {
    AggregateIterable<Document> aggregate = getDB().getCollection(collectionName).aggregate(
            Arrays.asList(
                    match(match.append(field, value))
                    , group("$" + field, Accumulators.sum("_count", 1))
                    , match(new Document("_count", new Document("$gte", minCount)))
            )
    );

    Document first = aggregate.first();
    return first == null ? false : true;
}
 
开发者ID:ysrc,项目名称:Liudao,代码行数:23,代码来源:MongoDao.java


示例14: testAggregate

import com.mongodb.client.model.Accumulators; //导入依赖的package包/类
@Test
public void testAggregate()
{
    List<Document> docList = new ArrayList<Document>();
    coll.aggregate(Arrays.asList(Aggregates.match(Filters.eq("name", "Alto")),
        Aggregates.group("color", Accumulators.sum("count", 1)))).into(docList);

    assertEquals(1, docList.size());

    docList.clear();

    Document first = coll
        .aggregate(Arrays.asList(Aggregates.match(Filters.eq("name", "Alto")),
            Aggregates.group("color", Accumulators.sum("count", 1))), Document.class)
        .allowDiskUse(true).batchSize(12).bypassDocumentValidation(true).collation(Collation.builder().build())
        .first();
    Assert.assertNotNull(first);

    first = coll
        .aggregate(Arrays.asList(Aggregates.match(Filters.eq("name", "Alto")),
            Aggregates.group("color", Accumulators.sum("count", 1))), Document.class)
        .allowDiskUse(true).batchSize(12).bypassDocumentValidation(true).collation(Collation.builder().build())
        .map(new Function<Document, Document>()
        {
            @Override
            public Document apply(Document t)
            {
                t.put("hello", "world");
                return t;
            }
        }).first();
    Assert.assertNotNull(first);

}
 
开发者ID:dd00f,项目名称:ibm-performance-monitor,代码行数:35,代码来源:ProfiledMongoClientTest.java


示例15: sum

import com.mongodb.client.model.Accumulators; //导入依赖的package包/类
public MongoAccumulator sum(String fieldName, String expression) {
    accumulators.add(Accumulators.sum(fieldName, expression));
    return this;
}
 
开发者ID:T-baby,项目名称:MongoDB-Plugin,代码行数:5,代码来源:MongoAccumulator.java


示例16: avg

import com.mongodb.client.model.Accumulators; //导入依赖的package包/类
public MongoAccumulator avg(String fieldName, String expression) {
    accumulators.add(Accumulators.avg(fieldName, expression));
    return this;
}
 
开发者ID:T-baby,项目名称:MongoDB-Plugin,代码行数:5,代码来源:MongoAccumulator.java


示例17: last

import com.mongodb.client.model.Accumulators; //导入依赖的package包/类
public MongoAccumulator last(String fieldName, String expression) {
    accumulators.add(Accumulators.last(fieldName, expression));
    return this;
}
 
开发者ID:T-baby,项目名称:MongoDB-Plugin,代码行数:5,代码来源:MongoAccumulator.java


示例18: max

import com.mongodb.client.model.Accumulators; //导入依赖的package包/类
public MongoAccumulator max(String fieldName, String expression) {
    accumulators.add(Accumulators.max(fieldName, expression));
    return this;
}
 
开发者ID:T-baby,项目名称:MongoDB-Plugin,代码行数:5,代码来源:MongoAccumulator.java


示例19: min

import com.mongodb.client.model.Accumulators; //导入依赖的package包/类
public MongoAccumulator min(String fieldName, String expression) {
    accumulators.add(Accumulators.min(fieldName, expression));
    return this;
}
 
开发者ID:T-baby,项目名称:MongoDB-Plugin,代码行数:5,代码来源:MongoAccumulator.java


示例20: push

import com.mongodb.client.model.Accumulators; //导入依赖的package包/类
public MongoAccumulator push(String fieldName, String expression) {
    accumulators.add(Accumulators.push(fieldName, expression));
    return this;
}
 
开发者ID:T-baby,项目名称:MongoDB-Plugin,代码行数:5,代码来源:MongoAccumulator.java



注:本文中的com.mongodb.client.model.Accumulators类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java PingData类代码示例发布时间:2022-05-22
下一篇:
Java Core类代码示例发布时间:2022-05-22
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap