MongoDB

建议参考官方文档真详细

Spring Data MongoDB - Reference Documentation

mangodb模糊查询用法

使用Spring访问Mongodb的方法大全——Spring Data MongoDB查询指南 - JadePeng - 博客园

字段下面的list中字段值的查询判断

query.addCriteria(Criteria.where("rulesItem.bussinessType.value").regex(reqDTO.getBussinessType(), "i"));

spring-data-mongodb之Aggregation -

排序后取出第一个

User findFirstByOrderByLastnameAsc();

User findTopByOrderByAgeDesc();

Page queryFirst10ByLastname(String lastname, Pageable pageable);

Slice findTop3ByLastname(String lastname, Pageable pageable);

List findFirst10ByLastname(String lastname, Sort sort);

List findTop10ByLastname(String lastname, Pageable pageable);


mango做聚合操作

mango

db.getCollection('agent').aggregate([ {$group: {_id : {"officeCode":"$officeCode", "segOrgn":"$segOrgn","segDstn:$segDstn"}, num: {$sum : 1}}} ])

java

public List aggregate()

{

Aggregation aggregation1 = Aggregation.newAggregation(Aggregation.group("officeCode:$officeCode","segOrgn:$segOrgn","segDstn:$segDstn").count().as("num"));

AggregationResults outputTypeCount1 =

        mongoTemplate.aggregate(aggregation1, "agent", AgentDO1.class);

List tagCount = outputTypeCount1.getMappedResults();

return tagCount;

}

mango有子列表做聚合操作

public List aggregateSales() {

Aggregation aggregation1 = Aggregation.newAggregation(Aggregation.unwind("resultList"),

Aggregation.group("startDate:$startDate","endDate:$endDate","officeCode:$resultList.officeCode", "segOrgn:$resultList.segOrgn", "segDstn:$resultList.segDstn").count().as("num"));

AggregationResults outputTypeCount1 = mongoTemplate.aggregate(aggregation1,

"sales_exception", SalesExceptionResultDO1.class);

List tagCount = outputTypeCount1.getMappedResults();

return tagCount;

}


mango 聚合实例

包括函数关联聚合查询

你可能感兴趣的:(MongoDB)