简体   繁体   English

Spring Data Mongodb和Spring Boot-从Mongolab自动装配MongoRepository

[英]Spring Data Mongodb & Spring Boot - autowiring MongoRepository from Mongolab

Let say I have a simple mongoRepository below: 假设我在下面有一个简单的mongoRepository:

public interface LettersRepository extends MongoRepository<Posts, String> { 

    }

I'm connecting to Mongolab. 我正在连接Mongolab。 The collection name on Mongolab has to be 'letters' for the autowiring to work. 为了使自动装配正常工作,Mongolab上的集合名称必须为“字母”。

Now, I don't want to call my collection on Mongolab 'letters'. 现在,我不想在Mongolab上将我的收藏称为“字母”。 I want to call it 'mails'. 我想称其为“邮件”。

How do I use annotations to configure that the autowiring will point to the 'mails' collection instead? 我如何使用注释来配置自动装配,而不是指向“邮件”集合?

I tried the annotation @Repository(value="mails") above the interface but it does not work. 我在界面上方尝试了注释@Repository(value="mails") ,但它不起作用。

The mapping to Mongo collections depends on your domain object, not the repository. 到Mongo集合的映射取决于您的域对象,而不是存储库。 If you want your Posts class to be stored in the collection mails , annotate it with @Document : 如果您希望Posts类存储在收款mails ,请使用@Document对其进行注释:

@Document(collection = "mails")
public class Posts {
}

See the Mapping chapter in the documentation for details. 有关详细信息,请参见文档中的“ 映射”一章。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM