private Mono<Void> ensureIndexesAndShards() {
        Map<TurmsMongoClient, List<MongoEntity<?>>> clientToEntities =
                CollectionUtil.newMapWithExpectedSize(clients.size());
        for (TurmsMongoClient client : clients) {
            clientToEntities.computeIfAbsent(client, key -> new LinkedList<>())
                    .addAll(client.getRegisteredEntities());
        }
        BiPredicate<Class<?>, CompoundIndex> customCompoundIndexFilter = (entityClass, index) -> {
            if (entityClass != Message.class) {
                return true;
            }
            boolean requiresConversationId = index.ifExist().length > 0
                    && index.ifExist()[0].equals(Message.Fields.CONVERSATION_ID);
            return requiresConversationId == useConversationId;
        };
        BiPredicate<String, Object> isCustomIndexEnabled = (fieldName, optionalIndex) -> {
            try {
                Field field = optionalIndex.getClass()
                        .getDeclaredField(fieldName);
                ReflectionUtil.setAccessible(field);
                return (boolean) field.get(optionalIndex);
            } catch (NoSuchFieldException e) {
                String message = "Could not find the field \""
                        + fieldName
                        + "\" in the optional index properties class: "
                        + optionalIndex.getClass()
                                .getName();
                throw new IllegalArgumentException(message, e);
            } catch (IllegalAccessException e) {
                // Should not happen
                throw new RuntimeException(e);
            }
        };
        BiPredicate<Class<?>, Field> customIndexFilter = (entityClass, field) -> {
            String fieldName = field.getName();
            if (entityClass == Admin.class) {
                return isCustomIndexEnabled.test(fieldName,
                        mongoGroupProperties.getAdmin()
                                .getOptionalIndex()
                                .getAdmin());
            } else if (entityClass == Group.class) {
                return isCustomIndexEnabled.test(fieldName,
                        mongoGroupProperties.getGroup()
                                .getOptionalIndex()
                                .getGroup());
            } else if (entityClass == GroupBlockedUser.class) {
                return isCustomIndexEnabled.test(fieldName,
                        mongoGroupProperties.getGroup()
                                .getOptionalIndex()
                                .getGroupBlockedUser());
            } else if (entityClass == GroupInvitation.class) {
                return isCustomIndexEnabled.test(fieldName,
                        mongoGroupProperties.getGroup()
                                .getOptionalIndex()
                                .getGroupInvitation());
            } else if (entityClass == GroupJoinRequest.class) {
                return isCustomIndexEnabled.test(fieldName,
                        mongoGroupProperties.getGroup()
                                .getOptionalIndex()
                                .getGroupJoinRequest());
            } else if (entityClass == GroupMember.class) {
                return isCustomIndexEnabled.test(fieldName,
                        mongoGroupProperties.getGroup()
                                .getOptionalIndex()
                                .getGroupMember());
            } else if (entityClass == Message.class) {
                return isCustomIndexEnabled.test(fieldName,
                        mongoGroupProperties.getMessage()
                                .getOptionalIndex()
                                .getMessage());
            } else if (entityClass == Meeting.class) {
                return isCustomIndexEnabled.test(fieldName,
                        mongoGroupProperties.getConference()
                                .getOptionalIndex()
                                .getMeeting());
            } else if (entityClass == UserFriendRequest.class) {
                return isCustomIndexEnabled.test(fieldName,
                        mongoGroupProperties.getUser()
                                .getOptionalIndex()
                                .getUserFriendRequest());
            } else if (entityClass == UserRelationship.class) {
                return isCustomIndexEnabled.test(fieldName,
                        mongoGroupProperties.getUser()
                                .getOptionalIndex()
                                .getUserRelationship());
            } else if (entityClass == UserRelationshipGroupMember.class) {
                return isCustomIndexEnabled.test(fieldName,
                        mongoGroupProperties.getUser()
                                .getOptionalIndex()
                                .getUserRelationshipGroupMember());
            } else {
                String message =
                        "Could not check if the custom index is enabled for the unknown class: "
                                + entityClass.getName();
                throw new IllegalArgumentException(message);
            }
        };
        return Mono.whenDelayError(clientToEntities.entrySet()
                .stream()
                .map(entry -> entry.getKey()
                        .ensureIndexesAndShards(entry.getValue()
                                .stream()
                                .map(MongoEntity::entityClass)
                                .collect(Collectors.toList()),
                                customCompoundIndexFilter,
                                customIndexFilter))
                .toList());
    }
@return True if all collections have existed
turms-service/src/main/java/im/turms/service/storage/mongo/MongoCollectionInitializer.java