Function collectDocuments