java - Spring integrates mongodb and reports a duplicate primary key error based on the primary key _id query
巴扎黑
巴扎黑 2017-05-24 11:35:45
0
1
1142

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. . .

巴扎黑
巴扎黑

reply all (1)
洪涛

I tested it and found out that there is a problem with the mongo version. Just change to a lower version. . .

    Latest Downloads
    More>
    Web Effects
    Website Source Code
    Website Materials
    Front End Template
    About us Disclaimer Sitemap
    php.cn:Public welfare online PHP training,Help PHP learners grow quickly!