Reputation: 7374
Code that I want to execute by 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?
Upvotes: 3
Views: 1958
Reputation: 1382
Yes, Spring Data MongoDB
have support for $merge
stage.
Your code can be executed by MongoTemplate
following way.
MergeOperation mergeOperation = Aggregation.merge()
.intoCollection("someCollection")
.on("_id")
.whenMatched(MergeOperation.WhenDocumentsMatch.mergeDocuments())
.whenNotMatched(MergeOperation.WhenDocumentsDontMatch.discardDocument())
.build();
Use this mergeOperation
with mongoTemplate
.
Upvotes: 5