[英]how to ignore _id and _class when write mongodb document?
I have one collection which stores time-series data, only insert and query, no update and delete, as MongoTemplate
genenrates _id
and _class
fields automatically, these two fields consume disk space and I don't need them, how can I ignore them when writing?我有一个存储时间序列数据的集合,只插入和查询,没有更新和删除,因为
MongoTemplate
会自动生成_id
和_class
字段,这两个字段占用磁盘空间,我不需要它们,我怎么能忽略它们写作?
PS: I know how to ignore _class globally, how to ignore _class only for one specific collection? PS:我知道如何全局忽略 _class,如何仅针对一个特定集合忽略 _class?
I'm not sure why you would want to enable the global _class & _id and disable it only certain conditions.我不确定您为什么要启用全局 _class 和 _id 并仅在某些条件下禁用它。
Anyway for the problem, if you want to discard those fields, you can just convert your POJO to a raw json and directly save it in Mongo.无论如何,如果您想丢弃这些字段,您可以将您的 POJO 转换为原始 json 并直接将其保存在 Mongo 中。
Document document = Document.parse(jsonString)
mongoTemplate.getCollection("collection").insertOne(document);
You can create a wrapper write method to incorporate these changes.您可以创建包装器写入方法来合并这些更改。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.