网站开发 方案 报价做技术网站赚钱
spring-data-mongodb与mongodb驱动有兼容性问题,不匹配会报NoSuchMethod异常,mongodb的java驱动包在4.0之后由mongodb-java-driver更名为mongodb-driver-sync。
spring-data-mongodb包依赖中有mongodb-driver-core,但缺诸如MongoCollection等类。
官方说明:Spring Data MongoDB - Reference Documentation
https://docs.spring.io/spring-data/mongodb/docs/4.2.0-M2/reference/html/#compatibility.matrix
官方文档更新的速度有限,比较新的版本没有reference文档,没得参考。

 
4.1以下的兼容性:
兼容性列表:

mongodb驱动与mongodb版本匹配列表如图,驱动和mongodb版本不匹配只是不能使用mongodb的新特性,不影响正常使用
|   Icon  |   Explanation  | 
|   ✓  |   All features are supported.  | 
|   ⊛  |   The Driver version will work with the MongoDB version, but not all new MongoDB features are supported.  | 
|   No mark  |   The Driver version is not tested with the MongoDB version.  | 

案例使用版本:
"spring-data-mongodb" : "org.springframework.data:spring-data-mongodb:3.4.5", "mongodb-driver-sync" : "org.mongodb:mongodb-driver-sync:4.6.1"
 
