merge documents with the same function