首页 > 解决方案 > 转换 MongoCollection到 DBCollection SpingBoot 1.5.4 到 2.1.0.RELEASE

问题描述

我已将 springBoot 版本从升级1.5.42.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 集合。那么有什么办法可以在两者之间进行转换吗?

标签: javadatabasemongodbspring-boot

解决方案


升级到 spring-boot 2.0.4 时有类似的问题,使用简单的演员。您可以将 MongoCollection 转换为 DBCollection。

DBCollection dbCollection = (DBCollection) mongoTemplate.getCollection("someCollection");

这不是最好的解决方案,但对我有用,因为那里没有太多的上下文。


推荐阅读