Hi @Vartika_Malguri,
Spring Data has syntax helpers for aggregation stages and operators. It looks like $unionWith has been supported by UnionWithOperation since Spring Data MongoDB 3.1 although this is not currently documented in the list of Spring Data’s Supported Aggregation Operators. That seems to be an oversight and I have reported as spring-data-mongodb #3938 in the GitHub issue queue.
I currently don’t have a Spring Data environment set up to test the exact translation of your query (or time to do so), but the Spring documentation includes some very helpful Aggregation Framework Examples which would be a good starting point.
If you get stuck trying to create your Spring Data query, please post a code snippet with any compilation/error message received in the community forums and someone with more experience may be able to help out.
Regards,
Stennie