Database

[{from:"A",to:"B",value:1},{from:"B",to:"A",value:3},{from:"C",to:"A",value:6},{from:"C",to:"A",value:10},{from:"A",to:"C",value:20}]

Query

db.collection.aggregate([{"$group":{"_id":{"$setUnion":[["$from"],["$to"]]},"volume":{"$sum":1}}}])

Result