Springboot With Mongodb Error while using find*() query

后端 未结 1 595
庸人自扰
庸人自扰 2021-01-17 19:37

I am getting the following error:

at com.aks.springStorage.SpringStorageApplication.main(SpringStorageApplication.java:22) [classes/:na]
Caused

相关标签:
1条回答
  • 2021-01-17 20:02
    @Document(collation="company")
    

    This looks like a typo and the cause of your issue. You try to set collection name, but instead of collection you use collation property: https://docs.mongodb.com/manual/reference/collation/

    The correct form of annotation would be:

    @Document(collection = "company")
    public class Company {
        // ...
    }
    

    Or simpler – since value is an alias for collection:

    @Document("company")
    public class Company {
        // ...
    }
    

    You can even completely omit collection name. In that case Spring will use class name as collection name:

    @Document // name of collection wil be "company", as per class name
    public class Company {
        // ...
    }
    

    The last example is why this was working for you with e.g. count queries, even though you did not provide collection name explicitly.

    0 讨论(0)
提交回复
热议问题