[英]Spring Data MongoDB: How to describe aggregation $merge with Spring Aggregation?
Code that I want to execute by MongoTemplate
:我想通过
MongoTemplate
执行的代码:
{
$merge: {
into: 'someCollection',
on: "_id",
whenMatched: 'merge',
whenNotMatched: 'discard'
}
}
I did not find any suitable methods that allow me to describe $merge
stage, have doubts if Spring Data MongoDB
even supports this stage?我没有找到任何合适的方法让我描述
$merge
阶段,怀疑Spring Data MongoDB
是否支持这个阶段?
Yes, Spring Data MongoDB
have support for $merge
stage.是的,
Spring Data MongoDB
支持$merge
阶段。 Your code can be executed by MongoTemplate
following way. MongoTemplate
可以通过以下方式执行您的代码。
MergeOperation mergeOperation = Aggregation.merge()
.intoCollection("someCollection")
.on("_id")
.whenMatched(MergeOperation.WhenDocumentsMatch.mergeDocuments())
.whenNotMatched(MergeOperation.WhenDocumentsDontMatch.discardDocument())
.build();
Use this mergeOperation
with mongoTemplate
.将此
mergeOperation
与mongoTemplate
一起使用。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.