简体   繁体   中英

Spring Data Mongodb & Spring Boot - autowiring MongoRepository from Mongolab

Let say I have a simple mongoRepository below:

public interface LettersRepository extends MongoRepository<Posts, String> { 

    }

I'm connecting to Mongolab. The collection name on Mongolab has to be 'letters' for the autowiring to work.

Now, I don't want to call my collection on Mongolab 'letters'. 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.

The mapping to Mongo collections depends on your domain object, not the repository. If you want your Posts class to be stored in the collection mails , annotate it with @Document :

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

See the Mapping chapter in the documentation for details.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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