Database

[{"id":"1234","documentType":"IV","balance":{"total":100,"openBalance":60,"paid":40}},{"id":"9012","documentType":"CM","balance":{"total":50,"applied":0,"available":50}}]

Query

db.collection.aggregate([{$set:{newdoc:{$cond:{if:{$eq:["$documentType","IV"]},then:{"total":"$balance.total","openBalance":"$balance.openBalance","totalAmountPaid":"$balance.paid"},else:{"total":"$balance.total","availableAmount":"$balance.available","appliedAmount":"$balance.applied"}}}}},{$replaceWith:{$mergeObjects:[{/** these fields from the main doc*/id:"$id",documentType:"$documentType"},/** this is the newly created doc*/"$newdoc"]}}])

Result