java - 转换 MongoCollection到 DBCollection SpingBoot 1.5.4 到 2.1.0.RELEASE
问题描述
我已将 springBoot 版本从升级1.5.4
到2.1.0.RELEASE
. 我有以下一段代码,它正在制造麻烦。
MongoCollection<Document> collection1 = mongoTemplate.getCollection(collection);
MapReduceCommand cmd = new MapReduceCommand(collection1, map, reduce, "sd", MapReduceCommand.OutputType.INLINE,
null);
MapReduceOutput out = collection1.mapReduce(cmd);
NowgetCollection()
方法返回 MongoCollection 并MapReduceCommand
接受 DB 集合。那么有什么办法可以在两者之间进行转换吗?
解决方案
升级到 spring-boot 2.0.4 时有类似的问题,使用简单的演员。您可以将 MongoCollection 转换为 DBCollection。
DBCollection dbCollection = (DBCollection) mongoTemplate.getCollection("someCollection");
这不是最好的解决方案,但对我有用,因为那里没有太多的上下文。
推荐阅读
- python - 你能在 Python 中编辑俄罗斯方块,这样你就不必反复按箭头键来移动对象了吗?
- attributes - 如何在 Items.xml Hybris 中为项目的 Map 属性设置默认值?
- java - Java Android NullPointerException。不知道有什么问题吗?
- javascript - React npm run build 每次都失败
- vbscript - 如何将文本文件的内容复制到剪贴板?
- javascript - 如何在 pos odoo 中获取库存数量
- css - CSS prefers-color-scheme 根本不适用于 chrome
- barcode - ZPL:(00)在人类可读但不是条形码
- docker - Docker-compose 多个服务监听同一个端口,不同的域
- javascript - Reactjs:React-router-dom 无法读取未定义的属性推送