refactor createDirectoryDoc
fix upsert function