SpringData MongoDB异常:org.springframework.data.mongodb.UncategorizedMongoDbException
使用Spring Data整合MongoDB,查询某集合中的所有文档时报错,报错详细信息如下:org.springframework.data.mongodb.UncategorizedMongoDbException: Query failed with error code 2 and error message ‘Field ‘locale’ is invalid in: { locale:
·
使用Spring Data
整合MongoDB
,查询某集合中的所有文档时报错,报错详细信息如下:
org.springframework.data.mongodb.UncategorizedMongoDbException: Query failed with error code 2 and error message ‘Field ‘locale’ is invalid in: { locale: “userList” }’ on server 121.41.57.xxx:27017; nested exception is com.mongodb.MongoQueryException: Query failed with error code 2 and error message ‘Field ‘locale’ is invalid in: { locale: “userList” }’ on server xxx:27017
报错原因(巨坑):@Document
使用collation
属性指定了某个集合,实际上应该是collection
,他们俩个名字很像,很容易弄错!
/**
* @description:
* @date: 2022/4/3 19:26
*/
@Document(collection = "userList") // collection一定不要写错了
public class UserVO {
private String _id;
private String name;
private String pwd;
private Integer age;
private Integer rownum;
...
}
改回来后就不报错了。
更多推荐
已为社区贡献8条内容
所有评论(0)