当前位置:网站首页>Mongodb usage
Mongodb usage
2022-06-11 11:17:00 【Grade III code farmer 666】
1. rely on
<!-- SpringBoot MongoDB -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-mongodb</artifactId>
</dependency>
2.mongoDB Pagination
@ApiOperation(value = " Query alert records and analyze photo information by page ", notes = "", httpMethod = "GET")
@RequestMapping(method = RequestMethod.GET, value = "/analysisSearchAll")
public Response<Page<AnalysisAlarm>> analysisSearchAll(@ApiIgnore Pager<AnalysisAlarm> pager, String deviceType, String startTime,
String endTime, String deviceId) {
Page<AnalysisAlarm> analysisAlarms = service.analysisSearchAll(pager, deviceType, startTime, endTime, deviceId);
return Response.put(analysisAlarms);
}
3. Pagination impl Realization
@Override
public Page<AnalysisAlarm> analysisSearchAll(Pager<AnalysisAlarm> pager, String deviceType, String startTime, String endTime,
String deviceId) {
Query query = new Query();
Sort sort = Sort.by(Direction.DESC, "create_time");
PageRequest pageable = PageRequest.of(pager.getPageNum() - 1, pager.getPageSize(), sort);
// Paging condition query : Time , equipment id, Alert type
if(StringUtil.isNotEmpty(startTime) && StringUtil.isNotEmpty(endTime)){
query.addCriteria(Criteria.where("create_time").gte(DateUtils.parseDate(startTime)).lte(DateUtils.parseDate(endTime)));
}
if (StringUtils.isNotBlank(deviceId)) {
query.addCriteria(Criteria.where("deviceID").is(deviceId));
}
if (StringUtils.isNotBlank(deviceType)) {
query.addCriteria(Criteria.where("warningType").is(deviceType));
}
query.addCriteria(Criteria.where("data_status").is(1));
// Total number of queries
long total = mongoTemplate.count(query, AnalysisAlarm.class);
// Paging query
List<AnalysisAlarm> analysisAlarmList = mongoTemplate.find(query.with(pageable), AnalysisAlarm.class);
// Set the result set , total
Page<AnalysisAlarm> analysisAlarmPage = new PageImpl(analysisAlarmList, pageable, total);
return analysisAlarmPage;
}
4. Delete
@Override
public int deleteBatch(List<String> ids) {
ids.forEach(d->{
Query query = new Query(Criteria.where("_id").is(d));
AnalysisAlarm one = mongoTemplate.findOne(query, AnalysisAlarm.class);
if (ObjectUtils.isEmpty(one)){
throw new BusinessException(" This collection has been deleted ");
}
Update update = new Update();
update.set("data_status",0);
mongoTemplate.updateFirst(query, update, AnalysisAlarm.class);
});
return 1;
}
5. details
@Override
public List<AnalysisAlarm> elavatorAction(String deviceId) {
Query query = new Query();
// Paging condition query : Time , equipment id, Alert type
if (StringUtils.isNotBlank(deviceId)) {
query.addCriteria(Criteria.where("deviceID").is(deviceId));
}
query.addCriteria(Criteria.where("data_status").is(1));
// adopt deviceId Inquire about
// find It's an array
List<AnalysisAlarm> analysisAlarms = mongoTemplate.find(query, AnalysisAlarm.class);
return analysisAlarms;
}
边栏推荐
- After 95, programmers in big factories were sentenced for deleting databases! Dissatisfied with the leaders because the project was taken over
- Use pydub to modify the bit rate of the wav file, and an error is reported: c:\programdata\anaconda3\lib\site packages\pydub\utils py:170: RuntimeWarning:
- Problems encountered when using nailing intranet to penetrate and upload PHP projects
- MyCat-分库分表
- Jerry's ble chip power supply range and anti burn chip measures [chapter]
- 错误的导航分类横条代码版本
- 杰理之BLE SPP 开启 pin_code 功能【篇】
- 使用Labelimg制作VOC数据集或yolo数据集的入门方法
- Processing of uci-har datasets
- Working principle analysis of rxjs fromEvent
猜你喜欢

Don't be a fake worker

DROID-SLAM: 用于单目双目RGBD相机的深度视觉SLAM

Interpretation of cube technology | past and present life of cube Rendering Design

Characteristics and classification of creation mode (single case, factory)

Xiao P weekly Vol.08

杰理之获取 BLE 查看代码异常复位等异常情况原因【篇】

命令模式--进攻,秘密武器

使用国产MCU(国民技术 N32G031F8S7) 实现 PWM+DMA 控制 WS2812

找到自己的优势,才能干活不累,事半功倍!

Why does a ddrx power supply design require a VTT power supply
随机推荐
找到自己的优势,才能干活不累,事半功倍!
想做钢铁侠?听说很多大佬都是用它入门的
2022健博会,北京大健康产业展,艾灸健康展,北京健康服务展
数据库系统概论 ---- 第二章 -- 关系数据库(2.1~2.3)(重要知识点)
Digital collection app applet official account source code
MySQL optimized learning diary 10 - locking mechanism
Vscade -- vscode multi window name is configured as project name
杰理之BLE SPP 开启 pin_code 功能【篇】
Problems encountered when using nailing intranet to penetrate and upload PHP projects
MyCat-分库分表
Is it safe for Xiaobai to open an account directly on the flush?
34. find the first and last positions of elements in the sorted array ●●
沒有財富就不能自由嗎?
Common construction and capacity operation of string class
Interpreting USB3.0 test items
Command mode - attack, secret weapon
杰理之获取 BLE OTA 双备份升级(只能用于 4Mbits 以上的芯片)【篇】
拆分数据---水平拆分和纵向拆分
【碎碎念】关于波长|波速|周期的想法
The application of the spingboot+quartrz production environment supports distributed, custom corn, reflective execution of multiple tasks