Query failed with error code 2 and error message ‘Field ‘locale‘ is invalid in: { locale: “recommend

目录

错误描述

 解决方法


错误描述

使用MongoDB的findOne()方法报错:

java.lang.RuntimeException: org.springframework.data.mongodb.UncategorizedMongoDbException: Query failed with error code 2 and error message 'Field 'locale' is invalid in: { locale: "recommend_user" }' on server localhost:27017; 

 解决方法

仔细检查一下,原来是在写实体类的时候,注解写错了!!

各位友友也赶快仔细的检查一下吧!

错误的

@Document(collation = "recommend_user")

正确的

@Document(collection = "recommend_user")

方法一:将collation 修改成collection

方法二:或者是什么都不写,它默认是collection

@Document("recommend_user")

这样就可以解决以上bug了。

emm...出现这个错误的很大概率是因为以上的粗心操作

猜你喜欢

转载自blog.csdn.net/zsy3757486/article/details/130052493