Spring Data MongoDB 消除 POJO's [英] Spring Data MongoDB eliminate POJO's

查看:40
本文介绍了Spring Data MongoDB 消除 POJO's的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的系统是动态遥测系统.我们有数百个不同的蜘蛛,它们都将遥测数据发送回 SpringBoot 服务器,一切都是动态的,由 Mongo 中的 json 文件驱动,包括 UI.我们不构建 UI,相反,各个团队可以根据自己的需要配置自己的 UI,所有这些都通过编辑 json 文档.

My system is a dynamic telemetry system. We have hundreds of different spiders all sending telemetry back to the SpringBoot server, Everything is dynamic, driven by json files in Mongo, including the UI. We don't build the UI, as opposed to individual teams can configure their own UI for their needs, all by editing json docs.

我们运行了大部分 UI,我开始了中间件部分.我们第一次使用 Spring Boot 和 Spring Data Mongo 以及几个 MQ 事件监听器.问题是 Spring Data.我开始阅读它的文档,我意识到文档没有解决没有 POJO 的使用它.我有这个奇妙的动态模型,如果遥测蜘蛛指示,每个用户每分钟都会发生变化,如果我尝试过,我无法将其束缚到 POJO.有没有办法将 Spring Data 与 Map 一起使用?

We have the majority of the UI running and i began the middleware piece. We are using Spring Boot for the first time along with Spring Data Mongo with several MQ listeners for events. The problem is Spring Data. I started reading the docs on it and I realized the docs do not address using it without POJO's. I have this wonderfully dynamic model that changes per user per minute if the telemetry spiders dictate, I couldn't shackle this to a POJO if I tried. Is there a way to use Spring Data with a Map?

从我的实验来看,最大的问题是没有办法告诉存储库类的 CRUD 例程,如果没有 POJO,要查询哪个集合.

It seems from my experiments that the big issue is there is no way to tell the CRUD routines of the repository class what collection to query without a POJO.

我的怀疑是否正确,因为这行不通,我最好放弃 Spring Data 并直接使用 Mongo 驱动程序吗?

Are my suspicions correct in that this won't work and am I better off ditching Spring Data and using the Mongo driver directly?

推荐答案

我不认为在使用 spring-data 时没有 pojo 就可以做到.你至少可以做的是这个

I don't think you can do it without a pojo when using spring-data. The least you could do is this

public interface NoPojoRepository extends MongoRepository<DummyPojo, String> {
}

并创建一个只有 id 和 Map 的虚拟 pojo.

and create a dummy pojo with just id and a Map.

@Data
public class DummyPojo {
  @Id
  private String id;
  private Map<String, Object> value;
}

由于这个值字段是一张地图,你可以存储几乎任何东西.

Since this value field is a map, you can store pretty much anything.

这篇关于Spring Data MongoDB 消除 POJO&amp;#39;s的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆