我目前在一个原型项目中工作,我们在一个非常有限的数据集上使用mongo db正则表达式查询,以执行“包含”搜索来执行全文搜索。因为我们的实体中有一些布尔型属性,所以我们希望持久化可读的、因此可搜索的字符串值(作为布尔JSON表示的附加或替代)。
假设我的实体看起来像这样:
public class Foo {
protected Boolean superPowers;
protected Boolean evil;
//some transitive persistence thingy
}在mongo db中,我想要这样的东西。
{
//omitting things for brevity here
superPowers: true,
evil: false,
description: "Super Hero"
}或
{
//omitting things for brevity here
superPowers: true,
evil: true,
description: "Villain"
}或者,现在也可以像这样(所以不计算组合)
{
//omitting things for brevity here
superPowers: "super powers", // if "true"
evil: "", // if false it is an empty string
}多谢你们的支持!
致以敬意,
索本
发布于 2018-05-30 21:07:58
您可以通过侦听BeforeSaveEvent来增加要编写的文档,在该and中,您将获得对域对象和从该域对象派生的文档的访问权限。
@Component
class AugmentingEventListener extends AbstractMongoEventListener<Foo> {
public void onBeforeSaveEvent(BeforeSaveEvent<Foo> event) {
// add fields to the document as needed
}
}在我们的reference documentation中可以找到更多关于这方面的信息。
https://stackoverflow.com/questions/50604597
复制相似问题