初学mongoDB,使用MongoTemplateupdateFirst 踩的一个坑。

大致环境:
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
数据库在 Linux虚拟机上 mongoDB 3.2.22

部分错误信息

java.lang.IllegalArgumentException: Collation not supported by wire version: 4
	at com.mongodb.internal.operation.OperationHelper.validateCollationAndWriteConcern(OperationHelper.java:134)
	at com.mongodb.internal.operation.OperationHelper.validateWriteRequestCollations(OperationHelper.java:174)
	at com.mongodb.internal.operation.OperationHelper.validateWriteRequests(OperationHelper.java:180)
	at com.mongodb.internal.operation.MixedBulkWriteOperation.validateWriteRequestsAndReleaseConnectionIfError(MixedBulkWriteOperation.java:518)
	at com.mongodb.internal.operation.MixedBulkWriteOperation.access$000(MixedBulkWriteOperation.java:71)
	at com.mongodb.internal.operation.MixedBulkWriteOperation$1.call(MixedBulkWriteOperation.java:183)
	at com.mongodb.internal.operation.MixedBulkWriteOperation$1.call(MixedBulkWriteOperation.java:180)
	at com.mongodb.internal.operation.OperationHelper.withReleasableConnection(OperationHelper.java:500)
	at com.mongodb.internal.operation.MixedBulkWriteOperation.execute(MixedBulkWriteOperation.java:180)
	at com.mongodb.internal.operation.MixedBulkWriteOperation.execute(MixedBulkWriteOperation.java:71)
	at com.mongodb.client.internal.MongoClientDelegate$DelegateOperationExecutor.execute(MongoClientDelegate.java:207)
	at com.mongodb.client.internal.MongoCollectionImpl.executeSingleWriteRequest(MongoCollectionImpl.java:1008)
	at com.mongodb.client.internal.MongoCollectionImpl.executeUpdate(MongoCollectionImpl.java:992)
	at com.mongodb.client.internal.MongoCollectionImpl.updateOne(MongoCollectionImpl.java:577)
	at org.springframework.data.mongodb.core.MongoTemplate.lambda$doUpdate$19(MongoTemplate.java:1652)
	at org.springframework.data.mongodb.core.MongoTemplate.execute(MongoTemplate.java:566)
	at org.springframework.data.mongodb.core.MongoTemplate.doUpdate(MongoTemplate.java:1625)
	at org.springframework.data.mongodb.core.MongoTemplate.updateFirst(MongoTemplate.java:1556)
	at com.service.Impl.UserServiceImpl.deposit(UserServiceImpl.java:65)
	at com.web.controller.UserController.deposit(UserController.java:63)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

错误的代码块
在这里插入图片描述
从报错信息和追溯了一下抛出错误的源码来看错误的原因是因为wire (mongoDB的网络协议)的版本问题,因此在网上找了一天关于网络协议的信息,最后都没有得到解决,就在我快绝望的时候,我尝试将User.class从mongoTemplate.updateFirest的构造函数中去除,结果错误就解决了

Logo

华为开发者空间,是为全球开发者打造的专属开发空间,汇聚了华为优质开发资源及工具,致力于让每一位开发者拥有一台云主机,基于华为根生态开发、创新。

更多推荐