博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
org.bson.codecs.configuration.CodecConfigurationException
阅读量:6881 次
发布时间:2019-06-27

本文共 1539 字,大约阅读时间需要 5 分钟。

hot3.png

mongodb的聚合查询,里面包含枚举类型的查询时, 要转成String再做查询,否则会报:

org.bson.codecs.configuration.CodecConfigurationException: Can't find a codec for class  ...

记录一下.

例如下例中的SearchLogType.USER.toString()

try {      Criteria rightIntervalCR = Criteria.where("time").lt(rightIntervalDate);      Criteria leftIntervalCR = Criteria.where("time").gte(leftIntervalDate);      Criteria onlineCR = Criteria.where("type").is(SearchLogType.USER.toString());//只查询线上问的日志      String[] groupUseFields = {"userid"};      AggregationOperation matchOperation = new MatchOperation(leftIntervalCR.andOperator(onlineCR, rightIntervalCR));      AggregationOperation groupOperation = new GroupOperation(Fields.fields(groupUseFields));      AggregationOperation[] aggregationOperations = new AggregationOperation[2];      aggregationOperations[0] = matchOperation;      aggregationOperations[1] = groupOperation;      Aggregation aggregation = Aggregation.newAggregation(aggregationOperations);      AggregationResults
aggregationResults = mongoOperation.aggregate(aggregation, logCollectionName, String.class); List
useridList = aggregationResults.getMappedResults(); if (useridList != null) { for (String userid : useridList) { JsonObject useridJsonObject = GsonFactory.getGsonClient().fromJson((String) userid, JsonObject.class); String useridStr = useridJsonObject.get("_id").getAsString(); } } } catch (Exception e) { e.printStackTrace(); }

 

 

转载于:https://my.oschina.net/airship/blog/2252081

你可能感兴趣的文章
EXCEL TIPS From Webs
查看>>
navicat 快捷键
查看>>
集成的HTTP嗅探器HttpWatch v11发布,支持Google Chrome丨附下载
查看>>
GIS软件开发包Map Suite v10.2.0发布,支持3D渲染
查看>>
TypeScript【Webpack 打包过】 编译过的代码怎么对源码调试?
查看>>
LSTM结构理解与python实现
查看>>
ownCloud + OneinStack 私有云搭建方案
查看>>
linux tomcat 无法关闭 :8005端口未启动
查看>>
Transaction marked as rollback-only异常
查看>>
MySql datetime 和 timestamp 区别
查看>>
window下配置vagrant与centos 与常用操作
查看>>
记一次HDFS Nameserver 死掉原因
查看>>
C#写Windows服务
查看>>
angular学习中踩过的坑
查看>>
2、MD5Utils
查看>>
Spring Boot JNDI:Spring Boot中怎么玩JNDI
查看>>
在mac上安装 docker
查看>>
JVM运行机制
查看>>
JVM GC 机制与性能优化 2 实例测试
查看>>
oracl 数据库中查询当前时间前几天的数据
查看>>