Scala Codecs help needed

Hello. I have the Mongo-Scala-Driver (4.3.1), I get runtime errors " [Can’t find a codec for class scala.Some]" if I leave the default codec as is. If I implement my codec as shown below, I get “Can’t find codec for class scala.None”. The similar problem was once raised on StackOverflow mongodb - Scala error: org.bson.codecs.configuration.CodecConfigurationException: Can't find a codec for class scala.Some - Stack Overflow
, but the solution is outdated.

Question: is my code below considered the correct way to implement a codec at modern 4.3.1. version? And could you write a codec for Scala.None type, I would like Bson None values to be present in Documents. Below you see class SomeCodec that handles only the Some() part of the Option, and the None part of Option is therefore not decoded and results in Runtime errors.

My implementation is below and has the Runtime error that it cannot decode class Scala.None

class SomeCodec extends Codec[Some[_]] {
  override def encode(writer: BsonWriter, value: Some[_], encoderContext: EncoderContext): Unit = value match {
    case Some(v: String) => writer.writeString(v)
    case Some(v: Int) => writer.writeInt32(v)
    case Some(v: Long) => writer.writeInt64(v)
    case Some(v: Boolean) => writer.writeBoolean(v)

  override def getEncoderClass: Class[Some[_]] = classOf[Some[_]]

  override def decode(reader: BsonReader, decoderContext: DecoderContext): Some[_] = {
    reader.getCurrentBsonType match {
      case BsonType.BOOLEAN => Some(reader.readBoolean())
      case BsonType.STRING => Some(reader.readString())
      case BsonType.INT64 => Some(reader.readInt64())
      case BsonType.INT32 => Some(reader.readInt32())

object MyMongoDBCodecs {
  val commentCodecProvider = Macros.createCodecProviderIgnoreNone[VkComment]
  val postCodecProvider = Macros.createCodecProviderIgnoreNone[VkPost]
  val likeCodecProvider = Macros.createCodecProviderIgnoreNone[VkLike]
  val groupCodecProvider = Macros.createCodecProviderIgnoreNone[VkGroup]
  val userCodecProvider = Macros.createCodecProviderIgnoreNone[VkUser]

  def getMyCodecProviders(mongoClientSettings: MongoClientSettings): CodecRegistry = {
    val codecRegistry = fromRegistries(fromProviders(commentCodecProvider), fromProviders(postCodecProvider),
      fromProviders(likeCodecProvider), fromProviders(groupCodecProvider), fromProviders(userCodecProvider),
      fromCodecs(new SomeCodec()),

In the code, I set my codec this way:

private val codecRegistry = MyMongoDBCodecs.getMyCodecProviders(mongoClientSettings)
private val db = mongoClient.getDatabase("dosug").withCodecRegistry(codecRegistry)

Looking forward to your replies.