Project as nested document in spring mongo(项目作为spring mongo中的嵌套文档)
本文介绍了项目作为spring mongo中的嵌套文档的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在寻找翻译来改变这个:
I'm looking for a translator to change this :
getCollection('migrate').aggregate([
{ "$project": {
"Contrat": {"Field1":"$Field1", "Field2":"$Field2"},
"Formule": {"Field3":"$Field3", "Field4":"$Field4"}
}},
{ "$project": {
"Contrats": {"Contrat":"$Contrat", "Formule":"$Formule"}
}}
])
到 MongoJava 聚合框架.类似的东西:
to MongoJava aggregation framework. Something like :
AggregationOperation project = Aggregation.project("Field1,Field2"); // while naming it "Contrat"
AggregationOperation project2 = Aggregation.project("Field3,Fiel4"); // while naming it Formule
AggregationOperation project3 = Aggregation.project("Contrat,Formule"); // while naming it " Contrats"
AggregationOperation out = Aggregation.out("test");
Aggregation aggregation = Aggregation.newAggregation(project, project2, project3, out);
mongoTemplate.aggregate(aggregation, "<nameOfInitialCollection>", Class.class);
我在文档中找不到我的答案,我认为这太差了,或者我可能太迷失了(|哑).
I can't find my answers in the documentation, which I think is too poor, or I may be too lost in it ( | dumb).
我会提前谢谢你.
推荐答案
你可以使用下面的聚合.
You can use below aggregation.
AggregationOperation project = Aggregation.project().
and("Contrat").nested(Fields.fields("Field1","Field2")).
and("Formule").nested(Fields.fields("Field3","Field4"));
AggregationOperation project2 = Aggregation.project().
and("Contrats").nested(Fields.fields("Contrat","Formule")).
AggregationOperation out = Aggregation.out("test");
Aggregation aggregation = Aggregation.newAggregation(project, project2, out);
mongoTemplate.aggregate(aggregation, "<nameOfInitialCollection>", Class.class);
这篇关于项目作为spring mongo中的嵌套文档的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
沃梦达教程
本文标题为:项目作为spring mongo中的嵌套文档


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