摘要:在使用Spring Boot操作Mongodb的时候,其中在通过时间段查询数据的时候遇到了这个异常,意思就是不能添加两个表达式,下面看下具体的异常信息和代码,以及最后的解决办法。

一:异常信息

"org.springframework.data.mongodb.InvalidMongoDbApiUsageException: Due to limitations of the com.mongodb.BasicDBObject, you can't add a second 'operateTime' expression specified as 'operateTime : { \"$lte\" : 1536249600000}'. Criteria already contains 'operateTime : { \"$gte\" : 1536076800000}'.\norg.springframework.data.mongodb.InvalidMongoDbApiUsageException: Due to limitations of the com.mongodb.BasicDBObject, you can't add a second 'operateTime' expression specified as 'operateTime : { \"$lte\" : 1536249600000}'. Criteria already contains 'operateTime : { \"$gte\" : 1536076800000}'.\n\tat org.springframework.data.mongodb.core.query.Criteria.setValue(Criteria.java:688)\n\tat org.springframework.data.mongodb.core.query.Criteria.getCriteriaObject(Criteria.java:621)\n\tat org.springframework.data.mongodb.core.query.Criteria.createCriteriaList(Criteria.java:678)\n\tat org.springframework.data.mongodb.core.query.Criteria.andOperator(Criteria.java:587)\n\tat boss.platform.log.provider.BizLogProviderImpl.getBizLogsList(BizLogProviderImpl.java:163)\n\tat boss.platform.log.provider.BizLogProviderImpl$$FastClassBySpringCGLIB$$604ab2fb.invoke(<generated>)\n\tat org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:204)\n\tat 

二:错误代码

if (param.get("startTime") != null && param.get("endTime") != null) {// 模糊查询 操作时间>=开始时间 操作时间<=结束时间long startTime = parseDateToLong((String) param.get("startTime") + " 00:00:00");long endTime = parseDateToLong((String) param.get("endTime") + " 23:59:59");// 在用时间段查询的遇到一个坑,上面是错误的写法criteria.and("operateTime").gte(startTime).and("operateTime").lte(endTime);
}

三:解决办法

if (param.get("startTime") != null && param.get("endTime") != null) {// 模糊查询 操作时间>=开始时间 操作时间<=结束时间long startTime = parseDateToLong((String) param.get("startTime") + " 00:00:00");long endTime = parseDateToLong((String) param.get("endTime") + " 23:59:59");// 在用时间段查询的遇到一个坑,上面是错误的写法/*criteria.and("operateTime").gte(startTime).and("operateTime").lte(endTime);*/// 下面的是正确的写法criteria.andOperator(Criteria.where("operateTime").gte(startTime),Criteria.where("operateTime").lte(endTime));}

Due to limitations of the com.mongodb.BasicDBObject, you can't add a second 'operateTime' expression相关推荐

  1. 【已解决】Due to limitations of the com.mongodb.BasicDocument, you can‘t add a second ‘$and‘ expression

  2. 解决MongoDB问题:Due to limitations of the com.mongodb.BasicDocument, you cant add a second null criter

    1.问题描述 Due to limitations of the com.mongodb.BasicDocument, you can t add a second null criteria. Qu ...

  3. 【Kafka】Kafka创建Topic的时候提示WARNING: Due to limitations in metric names, topics with a period ('.')

    1.概述 新建一个topic结果发现出了一个warn信息 (base) lcc@lcc kafka_2.11-1.1.0$ bin/kafka-topics.sh --create --zookeep ...

  4. Due to limitations in metric names, topics with a period ('.') or underscore ('_') could collide. To

    Due to limitations in metric names, topics with a period ('.') or underscore ('_') could collide. To ...

  5. Mongodb出现Error: couldn‘t add user: Could not find role: root@database 解决方法

    目录 1. 问题所示 2. 原理分析 3. 解决方法 1. 问题所示 在增加mongodb的账号密码时候,实现有误,提示无法增加role这个权限,但明明已经是root的最高权限 > use ad ...

  6. Java mongoDB查询(Query Criteria)

    MongoDB 将数据存储为一个文档,数据结构由键值(key=>value)对组成.MongoDB 文档类似于 JSON 对象.字段值可以包含其他文档,数组及文档数组. Query //添加过滤 ...

  7. mongoTemplate结合Criteria实现分页、模糊、二级嵌套和时间范围查询等

    点击这里 > Java实现MongoDB分页查询以及优化方案设计 @Transactionalpublic Result<PageResult<SubjectInfo>> ...

  8. BasicDBObject 和Query 查询mongodb不同使用方式

    一.使用BasicDBObject 进行查询 //查询条件设置 BasicDBObject queryCond = new BasicDBObject(); //单个字段 queryCond.put( ...

  9. mongodb排序_MongoDB排序

    mongodb排序 MongoDB sort method sorts the document in either ascending or descending order as specifie ...

  10. MongoDB+集成SpringBoot+索引+并发优化 - 基于《MongoDB进阶与实战:唐卓章》

    文章目录 MongoDB - 基于<MongoDB进阶与实战:唐卓章> 一.首次安装 服务安装 配置文件修改 可视化工具 Docker部署 二.基本使用 2.1 概念解析 2.2 Mong ...

最新文章

  1. 零基础参加Java培训班合适吗
  2. 私有属性可以被继承吗_妻子可以代位继承吗?
  3. 院士论坛|李德仁:测绘遥感与智能驾驶
  4. 程序员修炼之道:从小工到专家九月第一篇
  5. [转载]关于request和session详解
  6. JQuery 和JavaScript的区别
  7. mysql2005错误_SQL Server 2005 还原数据库错误解决方法
  8. 蓄水池问题c语言编程,蓄水池大作战
  9. 无意看到,当真给力!记住:永远不要在MySQL中使用UTF-8
  10. 稀疏组套索_Python中的稀疏组套索
  11. ubuntu上搭建php,ubuntu10.04上搭建php网站运行环境
  12. 自主生态再进一步,龙芯中科完成.NET3.1-LoongArch64平台研发
  13. static和extern的用法总结
  14. GO开发 -- could not launch process: decoding dwarf section info at offset 0x0: too short
  15. 《信息熵,联合熵,条件熵,交叉熵,相对熵》
  16. 如何在PowerShell中连接字符串和变量?
  17. alert点击完确定关闭浏览器窗口_为Microsoft Edge浏览器开启标签组功能
  18. VS2005 添加lib 的方法
  19. Sql Server卸载安装
  20. epcs1s是epcs1系列的么_串行FLASH配置芯片(EPCS1或EPCS4)数据手册

热门文章

  1. 数据服务面试题(某不知名企业 做高校大数据的)
  2. linux基本功系列之dd命令实战
  3. vagrant 启动错误
  4. Zotero 无法注册:显示“对服务器的请求已遭到某个扩展程序的阻止
  5. screeps world卡在nw.js界面
  6. IOS和小米手机拍照时旋转90度问题 针对一张图片 或者多张图片上传IOS卡顿问题解决方案分享
  7. 如何安装好cl /gcc ,运行C/C+文件
  8. 计算机男生都喜欢玩游戏,男生为什么都喜欢打游戏?真的是因为好玩吗?大错特错...
  9. js导出excel,修改table2excel源码支持导出的excel带边框
  10. shawl.qiu c# .net upload class v1.1