IllegalArgumentException:无效的BSON字段名称uuid

时间:2017-03-28 21:55:25

标签: mongodb scala illegalargumentexception mongo-scala-driver

所以我试过看似无数的东西才能让它发挥作用。当我打电话给 queueWrite 时, println语句给我这个:

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

和此:

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

哪个(我很确定)很好。然而,在打印之后,我得到了这个:

java.lang.IllegalArgumentException: Invalid BSON field name uuid

Afaik,字段名称uuid很好,关于我能找到的不正确名字的唯一事情就是确保 no'。中的符号(没有)

  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)

  }

任何想法/建议都会一如既往地受到高度赞赏:)

0 个答案:

没有答案