Database

[{"husband.firstName":"John","husband.secondName":"Smith","wife.firstName":"Alice","wife.secondName":"Watson"},{"husband.firstName":"Jack","husband.secondName":"Smith","wife.firstName":"Alice","wife.secondName":"Watson"}]

Query

db.collection.aggregate([{"$group":{"_id":{"husband":{"firstName":{"$getField":{"field":"husband.firstName","input":"$$ROOT"}},"secondName":{"$getField":{"field":"husband.secondName","input":"$$ROOT"}}},"wife":{"firstName":{"$getField":{"field":"wife.firstName","input":"$$ROOT"}},"secondName":{"$getField":{"field":"wife.secondName","input":"$$ROOT"}}}},"count":{"$sum":1}}},{"$sort":{"count":-1}}])

Result