How To Configure MongoDb Collection Name For a Class in Spring Data(如何为 Spring Data 中的类配置 MongoDb 集合名称)
问题描述
我的 MongoDB 数据库中有一个名为 Products
的集合,它由我的 Java 代码中的接口 IProductPrice
表示.以下存储库声明导致 Spring Date 查找集合 db.collection: Intelliprice.iProductPrice
.
I have a collection called Products
in my MongoDB database, which is represented by the interface IProductPrice
in my Java code. The following repository declaration causes Spring Date to look to the collection db.collection: Intelliprice.iProductPrice
.
我希望它使用外部配置将其配置为在 db.collection: Intelliprice.Products
中查找,而不是在 @Collection(..)
上添加注释代码>IProductPrice代码>.这可能吗?我该怎么做?
I want it to configure it to look in db.collection: Intelliprice.Products
using an external configuration rather than putting an @Collection(..)
annotation on IProductPrice
. Is this possible? How can I do this?
public interface ProductsRepository extends
MongoRepository<IProductPrice, String> {
}
推荐答案
目前唯一的方法是使用 collection
@Document 注释你的域类> 定义此类集合实例名称的属性应持久化.
The only way you can currently achieve this is by annotating your domain class with @Document
using the collection
property to define the name of the collection instances of this class shall be persisted to.
但是,有一个 JIRA 问题 建议添加一个可插入的命名策略来配置以更全局的方式处理类、集合和属性名称的方式.随意评论您的用例并投票.
However, there's a JIRA issue open that suggests adding a pluggable naming strategy to configure the ways class, collection and property names are handled in a more global way. Feel free to comment your use case and vote it up.
这篇关于如何为 Spring Data 中的类配置 MongoDb 集合名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何为 Spring Data 中的类配置 MongoDb 集合名称


- 如何使用WebFilter实现授权头检查 2022-01-01
- Eclipse 插件更新错误日志在哪里? 2022-01-01
- 将log4j 1.2配置转换为log4j 2配置 2022-01-01
- 从 finally 块返回时 Java 的奇怪行为 2022-01-01
- value & 是什么意思?0xff 在 Java 中做什么? 2022-01-01
- Jersey REST 客户端:发布多部分数据 2022-01-01
- Java包名称中单词分隔符的约定是什么? 2022-01-01
- Spring Boot连接到使用仲裁器运行的MongoDB副本集 2022-01-01
- C++ 和 Java 进程之间的共享内存 2022-01-01
- Safepoint+stats 日志,输出 JDK12 中没有 vmop 操作 2022-01-01