| | |
| | | package org.yeshi.utils.mongo; |
| | | |
| | | import org.springframework.data.mongodb.core.MongoTemplate; |
| | | import org.springframework.data.mongodb.core.aggregation.Aggregation; |
| | | import org.springframework.data.mongodb.core.aggregation.AggregationOperation; |
| | | import org.springframework.data.mongodb.core.aggregation.AggregationResults; |
| | | import org.springframework.data.mongodb.core.query.Criteria; |
| | | import org.springframework.data.mongodb.core.query.Query; |
| | | import org.springframework.data.mongodb.core.query.Update; |
| | |
| | | return (T) mongoTemplate.findById(id, this.getEntityClass()); |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 聚合查询 |
| | | * |
| | | * @param opts |
| | | * @param output |
| | | * @return |
| | | */ |
| | | public AggregationResults aggregate(List<? extends AggregationOperation> opts, Class output) { |
| | | Aggregation aggregation = Aggregation.newAggregation(opts); |
| | | return mongoTemplate.aggregate(aggregation, this.getEntityClass(), output); |
| | | } |
| | | |
| | | /** |
| | | * 通过主键删除 |
| | | * |