Ecoding of document with StringTranscoder failed


I am using couchbase with scala,my code looks like this

  def couch = Action {
 var s=

       case Success(value) =>value.get[StringDocument]("d1")
       case Failure(e) => e.printStackTrace

I am getting error as below

can anyone help me to solve this

Thank you in advance


I also tried like this

  def couch2 = Action {
    val s=

             case Success(value) =>value.getJsT[Acc]("age").map(json => Json.parse(json.toString))
        case Failure(e) => e.printStackTrace


but i am getting output as



Hey @an.sowmya,

I’d like to help but this code snippet is a little too isolated. Could you please give a more complete example? I.e. something I can C&P into a project and fully understand.

Error in couchbase with play 2.6

Though as a starting point you probably want to be using JsonDocument rather than StringDocument, as your content appears to be Json.


Hi @graham.pople ,

          Thank you for reply to my post

In couchbase i am storing document like this


I need to retreive the data in play framework(scala),

so i have written the action in the controller like this

package controllers
import{CouchbaseEnvironment, DefaultCouchbaseEnvironment}
import{N1qlQuery, N1qlQueryResult, N1qlQueryRow}
import{Bucket, Cluster, CouchbaseCluster}
import com.sandinh.couchbase.CBCluster
import com.typesafe.config.{Config, ConfigFactory}
import javax.inject.{Inject, Singleton}
import play.api.libs.json.Json
import play.api.mvc.{AbstractController, ControllerComponents}

import scala.util.{Failure, Success}

case class Acc(name: String, age: Option[Boolean])
object Acc { implicit val fmt = Json.format[Acc] }

  class CouchbaseController @Inject() (cc: ControllerComponents) extends AbstractController(cc) {
  val config = ConfigFactory.load()
  val cluster: CBCluster = new CBCluster (config)
  val accBucket = cluster.openBucket("acc")

 def couch = Action {
 val s=

       case Success(value) =>value.get[JsonDocument]("d1")
       case Failure(e) => e.printStackTrace

When i execute http://localhost:9000 /couch , i am getting output as ()

But now it is working for

  def couch3=Action{
   val    env:CouchbaseEnvironment=DefaultCouchbaseEnvironment.builder().connectTimeout(10000).build()
      val c: Cluster=CouchbaseCluster.create(env,"")
      val b:Bucket=c.openBucket("acc","Admin@123")


when i tried http://localhost:9000/couch3 ,i am getting o/p like



Hi @an.sowmya

Thanks for sending the more complete code through, it gives me a much better idea what’s going on. Now I’m not very familiar with Play so I could be wrong on this, but it looks like CBCluster are some Play-provided wrappers around the Couchbase API that seem to return Scala Futures. Your second example, the working one, uses the Couchbase API directly.

Your second example is also using the blocking Couchbase API (as a side note, we also have an asynchronous API based around the reactive library RxJava). My best guess is that you’re not correctly handling Play’s async Future’s in the first example, which is why that’s failing. Play probably has a way of streaming the results of a Future to the output, or you could use Await to block on the result.


This discussion has helped me clearing my doubts. Thanks.!


Thank you @graham.pople

I will try

asynchronous API based around the reactive library RxJava