1.mongoTemplate.findById(id, clazz, collectionName) query based on the primary key _id reports a nested exception is java.lang.NoClassDefFoundError: com/mongodb/MongoException$DuplicateKey
2. The problem is very strange. Some _ids can be found, no problem. Some _id checks will report the above error.
3. The mongodb used in the database uses spring to integrate mongodb and uses mongoTemplate to query.
4. The relevant configuration information is as follows:
org.springframework.data spring-data-mongodb 1.4.2.RELEASE org.springframework.data spring-data-commons 1.7.2.RELEASE org.springframework.data spring-data-commons-core 1.4.1.RELEASE org.mongodb mongo-java-driver 3.4.2
5.
6.@Override
public T findById(Serializable id, String collectionName) { return mongoTemplate.findById(id, clazz, collectionName); }
7. This error nested exception is java.lang.NoClassDefFoundError: com/mongodb/MongoException$DuplicateKey. There is no definite answer on the Internet. I hope someone knows the reason? My reason for this is strange. Some queries based on id are no problem. Some IDs report this error as soon as they are checked. depressed. . .
I tested it and found out that there is a problem with the mongo version. Just change to a lower version. . .