String subKey = getSubkey(key, dotPos, matchPos);
Object subObject = Utils.getListSafe(document, mainKey);
if (subObject instanceof BSONObject || subObject instanceof List<?>) {
removeSubdocumentValue(subObject, subKey, matchPos);
} else {
throw new MongoServerException("failed to remove subdocument");
}
} else {
Utils.removeListSafe(document, key);
}
}