org.bson.codecs.configuration.CodecConfigurationException

org.bson.codecs.configuration.CodecConfigurationException

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<String> aggregationResults = mongoOperation.aggregate(aggregation, logCollectionName, String.class);
      List<String> 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

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请联系我们举报,一经查实,本站将立刻删除。

发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/101353.html原文链接:https://javaforall.net

(0)
全栈程序员-站长的头像全栈程序员-站长


相关推荐

  • Android preference_android studio preview

    Android preference_android studio preview以前我们经常使用PreferenceActivity来显示给用户一个选项设置的界面,而现在Google推荐用PreferenceFragment来代替使用.先来看看官方文档的描述:Thepreferencehierarchycanbeformedinmultipleways:FromanXMLfilespecifyingthehierarchyFro

    2025年9月1日
    7
  • 给Android程序猿的六个建议

    给Android程序猿的六个建议

    2022年2月1日
    46
  • 【其他记录】Office2019专业增强版与Visio2016不能共存的解决办法

    【其他记录】Office2019专业增强版与Visio2016不能共存的解决办法office2019的安装技术是即点即用,visio2016的安装技术是windowsinstaller。(我下载的是这样)本来是先安装好了office2019,接着安装visio2016,显示无法安装visio2016。原因是:即点即用和windowsinstaller的程序不能并存,一次只能安装一种类型。一种简单的解决办法是:把office2019和visio2016全部卸载干净,…

    2022年7月19日
    28
  • lua字符串截取_lua删除数组元素

    lua字符串截取_lua删除数组元素localstr=”helloworld!”string.sub(str,1,string.len(str)-1)–hellowordstring.sub(str,起始位置,整个字符串的长度)–获取指定位置长度的字符串string.len(目标字符串)–获取字符串的长度

    2022年10月6日
    2
  • 开始laravel项目+理解

    开始laravel项目+理解一.laravel运行理解Ⅰ.开始,public/index.php此文件有两个作用。①:作为入口的起点,引导构建服务所需要的一切(包括路由,服务容器之类的)。②:作为所有请求的必经之路。请求经过此文件,会被“指派”到合适的路由,中间件等等进行处理。tips:所以用phpstudy的时候,记得设置一下①指定项目的根目录。②指定下路由。我用的nginx,设置的vhost.config文件。画起第一行用以指定项目的根目录,就apache的www文件的意思。第二行是指定所有请求最终会定向

    2022年5月7日
    39
  • Python基本特殊方法之__format__

    __format__()方法__format__()传参方法:someobject.__format__(specification)specification为指定格式,当应用程序中出现&quo

    2021年12月19日
    47

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

关注全栈程序员社区公众号