I'm currently playing around with Akka Streams and the Alpakka MongoDB connector.
Is it possible to specify the type for MongoSource
?
val codecRegistry = fromRegistries(fromProviders(classOf[TodoMongo]), DEFAULT_CODEC_REGISTRY)
private val todoCollection: MongoCollection[TodoMongo] = mongoDb
.withCodecRegistry(codecRegistry)
.getCollection("todo")
I would like to do something like this:
val t: FindObservable[Seq[TodoMongo]] = todoCollection.find()
MongoSource(t) // Stuck here
But I get the following error:
Expected Observable[scala.Document], Actual FindObservable[Seq[TodoMongo]].
I can't find the correct documentation about this part.
This is not published yet, but in Alpakka's master branch,
MongoSource.apply
takes a type parameter:Therefore, with the upcoming 0.18 release of Alpakka, you'll be able to do the following:
Note that
source
here assumes thattodoCollection.find()
returns anObservable[TodoMongo]
; adjust the types as needed.In the meantime, you could simply add the above code manually. For example:
Note that
MyMongoSource
is defined to reside in theakka.stream.alpakka.mongodb.scaladsl
package (likeMongoSource
), becauseObservableToPublisher
is a package-private class. You would useMyMongoSource
in the same way that you would useMongoSource
: