0

I am trying to migrate from Couchbase Java-sdk 2.7.23 to 3.x. Can't resolve flatMap with the below in Scala.

Unable to resolve flatMap() while fetching multiple documents from Couchbase

val reactiveCollection = bucket.scope("default").collection("default").reactive()
val docsToFetch = util.Arrays.asList("doc1", "doc2").toList

val fetchedResult: List[GetResult] = Flux.fromIterable(docsToFetch)
  .flatMap(key => reactiveCollection.get(key))
  .collectList()
  .block()
Pavel Ajtkulov
  • 515
  • 7
  • 21
S K
  • 1
  • 1

1 Answers1

0

There is nothing wrong with the flatMap function. Only thing you need to do is convert java list to scala list as below

  val reactiveCollection = bucket.scope("default").collection("default").reactive
  val docsToFetch: util.List[String] = java.util.Arrays.asList("doc1", "doc2")

  import scala.collection.JavaConverters._

  val fetchedResult: List[GetResult] = Flux.fromIterable(docsToFetch)
    .flatMap { key => reactiveCollection.get(key) }
    .collectList()
    .block().asScala.toList
Manoj Kumar
  • 68
  • 1
  • 7
  • I tried to convert to scala list by adding 'asScala.toList'. But, JavaConverters remain unused and no error is thrown for "asScala.toList". My Scala version is 2.11.12, anyother suggestions? – S K Jun 30 '23 at 05:59