database: Add private find_unique_doc_id and find_unique_document functions