当前位置:网站首页>mongoTemplate - distinct 使用
mongoTemplate - distinct 使用
2022-06-29 17:40:00 【iiaythi】
mongoTemplate - findDistinct 使用
场景
使用 findDistinct 统计订单数
api:
@Override
public <T> List<T> findDistinct(Query query, String field, Class<?> entityClass, Class<T> resultClass) {
return findDistinct(query, field, getCollectionName(entityClass), entityClass, resultClass);
}
参数:
- 查询
- 唯一字段
- 文档
- 返回结果类型
List<String> list = mongoTemplate.findDistinct(query, "orderId", OrderDocument.class, String.class);
在使用 distinct 时报错:
readString can only be called when CurrentBSONType is STRING, not when CurrentBSONType is INT32
原因
orderId 字段在定义时为 Integer 类型,所以会报类型转换失败
解决方案
List<Integer> list = mongoTemplate.findDistinct(query, "orderId", OrderDocument.class, Integer.class);
边栏推荐
- 传承中华美德,关注中老年大健康,育润奶粉敬老情浓
- Does MySQL support foreign keys
- regular expression
- What is the function of MySQL cursors
- Inherit Chinese virtues, pay attention to the health of the middle-aged and the elderly, and Yurun milk powder has strong respect for the elderly
- Automatic vending machine
- R语言ggplot2可视化:使用patchwork包(直接使用加号+)将两个ggplot2可视化结果横向组合、接着再和第三个图像横向组合起来(三幅图各占比例为50%、25%、25%)
- R语言ggplot2可视化:使用patchwork包(直接使用加号+)将一个ggplot2可视化结果和一个plot函数可视化结果横向组合起来形成最终结果图
- [webdriver] upload files using AutoIT
- R language uses user-defined functions to write deep learning linear activation functions and visualize linear activation functions
猜你喜欢

How to solve the 2003 error of MySQL in Linux

SRM supplier collaborative management system function introduction

基于STM32F103ZET6库函数串口实验

Walk with love, educate and run poor families, and promote public welfare undertakings

Does MySQL support foreign keys

如何使用B/S开发工具DevExtreme的图表控件 - 自定义轴位置?

传承中华美德,关注中老年大健康,育润奶粉敬老情浓

Online text digit recognition list summation tool

MySQL触发器如何创建与删除

How to solve MySQL 1045 error in Linux
随机推荐
How to use interrupt
The R language uses the KAP function (kap.2.raters function) of epidisplay package to calculate the value of kappa statistics (total consistency, expected consistency), analyze the consistency of the
R language uses user-defined functions to write deep learning linear activation functions and visualize linear activation functions
使用 SSH 方式拉取代码
What role does the supply chain management system play in the supply chain scenario?
R language uses GLM of mass package The Nb function establishes the negative binomial generalized linear model, and the summary function obtains the summary statistical information of the negative bin
MySQL触发器如何创建与删除
DevCloud加持下的青软,让教育“智”上云端
R language ggplot2 visualization: use the patchwork package (directly use the plus sign +) to horizontally combine a ggplot2 visualization result and a plot function visualization result to form the f
Fill in the next right node pointer of each node [make good use of each point - > reduce the space-time complexity as much as possible]
mysql.sock的概念是什么
Maidong Internet won the bid of Dajia Insurance Group
自定义HandlerInterceptor拦截器实现用户鉴权
分割回文串[dp + dfs组合]
Issue 42: is it necessary for MySQL to have multiple column partitions
Redux源码分析之createStore
R语言epiDisplay包的aggregate函数将数值变量基于因子变量拆分为不同的子集,计算每个子集的汇总统计信息、aggregate.data.frame函数包含缺失值的情况下分组统计结果为NA
【Try to Hack】Cookie和Session
SRM系统可以为企业带来什么价值?
正则表达式