[英]org.springframework.data.mongodb.UncategorizedMongoDbException Exception in Spring Boot MongoDB
Cannot understand why this exception is happening无法理解为什么会发生此异常
org.springframework.data.mongodb.UncategorizedMongoDbException: Query failed with error code 2 and error message 'Field 'locale' is invalid in: { locale: "Book" }' on server localhost:27017; nested exception is com.mongodb.MongoQueryException: Query failed with error code 2 and error message 'Field 'locale' is invalid in: { locale: "Book" }' on server localhost:27017
at org.springframework.data.mongodb.core.MongoExceptionTranslator.translateExceptionIfPossible(MongoExceptionTranslator.java:140)
at org.springframework.data.mongodb.core.MongoTemplate.potentiallyConvertRuntimeException(MongoTemplate.java:2899)
at org.springframework.data.mongodb.core.MongoTemplate.executeFindMultiInternal(MongoTemplate.java:2824)
at org.springframework.data.mongodb.core.MongoTemplate.findAll(MongoTemplate.java:1779)
at org.springframework.data.mongodb.core.MongoTemplate.findAll(MongoTemplate.java:1774)
at com.aditya.books.repository.CustomBookRepository.findAll(CustomBookRepository.java:18)
at com.aditya.books.repository.CustomBookRepository$$FastClassBySpringCGLIB$$66917159.invoke(<generated>)
at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:218)
at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.invokeJoinpoint(CglibAopProxy.java:779)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:163)
at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.proceed(CglibAopProxy.java:750)
at org.springframework.dao.support.PersistenceExceptionTranslationInterceptor.invoke(PersistenceExceptionTranslationInterceptor.java:137)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186)
at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.proceed(CglibAopProxy.java:750)
at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:692)
at com.aditya.books.repository.CustomBookRepository$$EnhancerBySpringCGLIB$$2414047e.findAll(<generated>)
Book Model书型
public class Book {
@Id
@JsonProperty(value = "bookID")
private long id;
private String title;
private String authors;
private String average_rating;
private String isbn;
private String language_code;
private String ratings_count;
private String price;
}
This is happening when I am calling findAll method from MongoRepository.当我从 MongoRepository 调用 findAll 方法时会发生这种情况。 I have checked data in DB also and everything seems fine and there is no field with name 'locale'我也检查了数据库中的数据,一切似乎都很好,并且没有名称为“locale”的字段
NVM , I found the error I was using NVM ,我发现了我使用的错误
@Document(collation= "Book")
instead of代替
@Document(collection = "Book")
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.