MongoDao.java 文件源码

java
阅读 32 收藏 0 点赞 0 评论 0

项目:Liudao 作者:
/**
 * 统计值 是否在统计结果(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;
}
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号