private void applyShardKey(BsonDocument filter, ShardKey shardKey, BsonDocument document) {
        List<ShardKey.Path> paths = shardKey.paths();
        for (ShardKey.Path shardKeyPath : paths) {
            if (shardKeyPath.isIdField()) {
                filter.append(DomainFieldName.ID, document.get(DomainFieldName.ID));
                continue;
            }
            String[] path = shardKeyPath.path();
            // fast path
            int pathLength = path.length;
            if (pathLength == 0) {
                throw new IllegalArgumentException(
                        "The path ("
                                + shardKeyPath
                                + ") must have one part at least");
            }
            if (pathLength == 1) {
                BsonValue shardKeyValue = document.get(path[0]);
                if (shardKeyValue != null) {
                    filter.append(path[0], shardKeyValue);
                }
            } else {
                // slow path
                BsonDocument currentPath = document;
                for (int i = 0; i < pathLength; i++) {
                    String p = path[i];
                    BsonValue shardKeyValue = currentPath.get(p);
                    if (shardKeyValue == null) {
                        break;
                    }
                    if (i == pathLength - 1) {
                        filter.append(shardKeyPath.fullPath(), shardKeyValue);
                    } else if (shardKeyValue.isDocument()) {
                        currentPath = shardKeyValue.asDocument();
                    } else {
                        break;
                    }
                }
            }
        }
    }
apply the shard key to the filter so that mongos know to which MongoDB the command needs to
be sent for better performance
turms-server-common/src/main/java/im/turms/server/common/storage/mongo/operation/TurmsMongoOperations.java