[英]Spring Data MongoDB: How to describe aggregation $merge with Spring Aggregation?
我想通過MongoTemplate
執行的代碼:
{
$merge: {
into: 'someCollection',
on: "_id",
whenMatched: 'merge',
whenNotMatched: 'discard'
}
}
我沒有找到任何合適的方法讓我描述$merge
階段,懷疑Spring Data MongoDB
是否支持這個階段?
是的, Spring Data MongoDB
支持$merge
階段。 MongoTemplate
可以通過以下方式執行您的代碼。
MergeOperation mergeOperation = Aggregation.merge()
.intoCollection("someCollection")
.on("_id")
.whenMatched(MergeOperation.WhenDocumentsMatch.mergeDocuments())
.whenNotMatched(MergeOperation.WhenDocumentsDontMatch.discardDocument())
.build();
將此mergeOperation
與mongoTemplate
一起使用。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.