title: Mongo-Scala-Driver: CodecConfigurationException: can't find a codec for class immutable.Document
body: <p><strong>Error message:</strong></p>
  
  <pre><code>org.bson.codecs.configuration.CodecConfigurationException: Can't find a codec for class org.mongodb.scala.bson.collection.immutable.Document
  </code></pre>
  
  <p><strong>Code:</strong></p>
  
  <pre><code>def queueWrite(collection: String, filter: Map[String, () =&gt; String], data: Map[String, () =&gt; String]) {
      val col = collections.get(collection).get
  
      val filterBson = Document()
      filter.foreach(f =&gt; { filterBson.append(f._1, f._2.apply) })
  
      val dataBson = Document()
      data.foreach(f =&gt; { dataBson.append(f._1, f._2.apply) })
  
      val options = new FindOneAndUpdateOptions
      options.returnDocument(ReturnDocument.AFTER)
      options.upsert(true)
  
      val observer = new Observer[Document] {
        override def onNext(doc: Document) = println(doc.toJson)
        override def onError(e: Throwable) = e.printStackTrace
        override def onComplete = println("onComplete")
      }
  
      val observable: Observable[Document] = col.findOneAndUpdate(filterBson, dataBson, options)
      observable.subscribe(observer)
  
    }
  </code></pre>
  
  <p><strong>Called with:</strong></p>
  
  <pre><code>val filter = Map[String, () =&gt; String]("uuid", p.getUniqueId.toString)
  
  var dataMap = Map[String, () =&gt; String]()
  dataMap = dataMap.+("uuid" -&gt; p.getUniqueId.toString)
  dataMap = dataMap.+("nickname" -&gt; p.getDisplayName)
  
  queueWrite("players", filter, dataMap)
  </code></pre>
  
  <hr>
  
  <hr>
  
  <p>I've tried using mutable documents but then realized that findoneandupdate returns an immutable. I also tried using a BsonDocument for the filter with equal but that ofc had no effect. I'm not really sure where to go from here, any help would be greatly appreciated :)</p>