Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

303
Views
¿Cómo convierto mi secuencia de comandos de agregación de MongoDB en un código java spring webflux para usar con mongoTemplete?

La idea es unir los cobros de pago y devolución , transformarlo en un nuevo cobro llamado transacción, el cual tendrá el resultado de esta unión.

mi guion

 db.payment.aggregate([ { $replaceRoot: { newRoot: { "_id": "$_id", "type": "payment", "payment": "$$ROOT" } } }, { $unionWith: { coll: "refund", pipeline: [ { $replaceRoot: { newRoot: { "_id": "$_id", "type": "refund", "refund": "$$ROOT" } } } ]} } ])

Este script funciona perfectamente.

mi codigo java

 List<AggregationOperation> list = new ArrayList<>(); ReplaceRootOperation replecePayment = replaceRoot() .withValueOf( ObjectOperators.valueOf("payment").mergeWith(Aggregation.ROOT) ); UnionWithOperation unionWithOperation = UnionWithOperation .unionWith("refund") .pipeline( replaceRoot().withValueOf( ObjectOperators.valueOf("refund").mergeWith(Aggregation.ROOT) ) ); LimitOperation limitOperation = Aggregation.limit(pageSize); list.add(replecePayment); list.add(unionWithOperation); list.add(limitOperation); Aggregation aggregation = newAggregation(Transaction.class, list); Flux<Transaction> output = mongoTemplate .aggregate(aggregation, "payment", Transaction.class); Transaction transaction = output.blockFirst();

El objeto no me regresa como esperaba, creo que el problema es ReplaceRootOperation. No encontré ningún ejemplo similar con lo que necesito para mi caso, así que lo implementé de esa manera solo con fines de prueba.

Mi resultado en este momento

 Transaction(id=359fd8a7-2228-40f1-95dc-e52554f5df21, type=null, payment=null, refund=null)
over 4 years ago · Santiago Trujillo
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!