4

So I've tried seemingly countless things to get this to work. When I call queueWrite, the println statements give me this:

{ "uuid" : "49f2-0b64-4bf3-49f2a35b-bbe8-4954f742d88b" }

and this:

{ "uuid" : "49f2-0b64-4bf3-49f2a35b-bbe8-4954f742d88b", "name" : "personName", "key" : "3E6A" }

Which (I'm pretty sure) is just fine. However, after it prints, I get this:

java.lang.IllegalArgumentException: Invalid BSON field name uuid

Afaik, the field name uuid is fine, the only things about an improper name I could really find is to just make sure there are no '.' symbols in it (which there aren't)

  def queueWrite(collection: String, filter: Map[String, () => String], data: Map[String, () => String]) {
    val col = collections.get(collection).get

    val filterDoc = new BsonDocument
    filter.foreach(f => { filterDoc append (f._1, new BsonString(f._2.apply)) })
    val filterBson = Document(filterDoc)
    println("filter: \n" + filterBson.toJson)

    val dataDoc = new BsonDocument
    data.foreach(f => { dataDoc append (f._1, new BsonString(f._2.apply)) })
    val dataBson = Document(dataDoc)
    println("data: \n" + dataBson.toJson)

    val options = new FindOneAndUpdateOptions
    options.returnDocument(ReturnDocument.AFTER)
    options.upsert(true)

    val observer = new Observer[Document] {
      override def onSubscribe(s: Subscription) = s.request(1)
      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)

  }

Any ideas / suggestions are greatly appreciated as always :)

annon
  • 107
  • 1
  • 11

0 Answers0