Springdata mongodb 版本兼容 引起 Error [The 'cursor' option is required, except for aggregate with the explain argument

时间:2023-03-09 16:38:19
Springdata mongodb 版本兼容 引起 Error [The 'cursor' option is required, except for aggregate with the explain argument

在Spring data mongodb 中使用聚合抛出异常 mongodb版本 为 3.6

org.springframework.dao.InvalidDataAccessApiUsageException: Command execution failed:  Error [The 'cursor' option is required, except for aggregate with the explain argument] 

Spring data mongodb 版本

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-mongodb</artifactId>
<version>1.5.8.RELEASE</version>
</dependency>

升级 mongodb-driver 为 3.6 并不能解决问题

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-mongodb</artifactId>
<exclusions>
<exclusion>
<groupId>org.mongodb</groupId>
<artifactId>mongodb-driver</artifactId>
</exclusion>
</exclusions>
</dependency> <dependency>
<groupId>org.mongodb</groupId>
<artifactId>mongodb-driver</artifactId>
<version>3.6.0-beta2</version>
</dependency>

把mongodb 版本降级为 3.4 即可

这贴出yum 源

mongodb 3.4

3.4
1. vi /etc/yum.repos.d/mongodb-3.4.repo  
[mongodb-org-3.4]
name=MongoDB Repository
baseurl=https://repo.mongodb.org/yum/redhat/$releasever/mongodb-org/3.4/x86_64/
gpgcheck=0
enabled=1
gpgkey=https://www.mongodb.org/static/pgp/server-3.2.asc

mongodb 3.6

2. vim /etc/yum.repos.d/mongodb-org-3.4.repo  
3. [mongodb-org-3.4]  
4. name=MongoDB Repository  
5. baseurl=https://repo.mongodb.org/yum/redhat/$releasever/mongodb-org/3.4/x86_64/  
6. gpgcheck=0  
7. enabled=1  
gpgkey=https://www.mongodb.org/static/pgp/server-3.4.asc 

虽然仓库写的是3.4 ,实际上会下载新版本的3.6

依赖关系解决

==============================================================================================================================================================================================================================================================================
Package 架构 版本 源 大小
==============================================================================================================================================================================================================================================================================
正在删除:
mongodb-org x86_64 3.6.0-0.1.rc0.el7 @mongodb-org-3.4 0.0
mongodb-org-mongos x86_64 3.6.0-0.1.rc0.el7 @mongodb-org-3.4 31 M
mongodb-org-server x86_64 3.6.0-0.1.rc0.el7 @mongodb-org-3.4 56 M
mongodb-org-shell x86_64 3.6.0-0.1.rc0.el7 @mongodb-org-3.4 31 M
mongodb-org-tools x86_64 3.6.0-0.1.rc0.el7 @mongodb-org-3.4 152 M 事务概要
=============================================================================================================================================================================================================================================================================