0

I am trying to use https://doc.akka.io/docs/alpakka/current/mongodb.html as the following:

import akka.actor.ActorSystem
import akka.stream.ActorMaterializer
import cats.data.Chain
import com.mongodb.reactivestreams.client.MongoClients
import org.mongodb.scala.bson.codecs.DEFAULT_CODEC_REGISTRY
import org.mongodb.scala.bson.codecs.Macros._

object Main extends App {
  implicit val system = ActorSystem()
  implicit val mat = ActorMaterializer()

  val preFailure = MsgPreFailure("Hello", Chain("Foo", "Too"))
  val codecRegistry = fromRegistries(fromProviders(classOf[MsgPreFailure]), DEFAULT_CODEC_REGISTRY)

  private val client = MongoClients.create("mongodb://localhost:27017")
  private val db = client.getDatabase("MongoSourceSpec")
  private val preFailureColl = db
    .getCollection("numbers", classOf[MsgPreFailure])
    .withCodecRegistry(codecRegistry)
} 

and the compiler complains:

[error] /home/developer/scala/trymongo/src/main/scala/Main.scala:15:23: not found: value fromRegistries
[error]   val codecRegistry = fromRegistries(fromProviders(classOf[MsgPreFailure]), DEFAULT_CODEC_REGISTRY)
[error]                       ^
[error] /home/developer/scala/trymongo/src/main/scala/Main.scala:15:38: not found: value fromProviders
[error]   val codecRegistry = fromRegistries(fromProviders(classOf[MsgPreFailure]), DEFAULT_CODEC_REGISTRY)
[error]                                      ^ 

What am I missing? The project can be find here https://gitlab.com/playscala/trymongo

softshipper
  • 32,463
  • 51
  • 192
  • 400

1 Answers1

2

I think you might need to import it, Try importing :

import org.bson.codecs.configuration.CodecRegistries.{fromProviders, fromRegistries}
Shivansh
  • 3,454
  • 23
  • 46