Having the following clause:
collection.updateOne(
Filters.and(myFilters: _*),
Document(
"$setOnInsert" -> Document(
"field" -> item.getAs[List[Map[String, String]]]("field")
)
),
UpdateOptions().upsert(true)
)
On the $setOnInsert
clause it will complain with Cannot resolve overloaded method 'Document'
, and as far as I’ve been checking the method signature for a Document
probably it isn’t resolving it as a CanBeBsonElements
.
Full trace of the error:
overloaded method value apply with alternatives:
(underlying: org.mongodb.scala.bson.BsonDocument)org.mongodb.scala.bson.collection.immutable.Document <and>
(elems: org.mongodb.scala.bson.BsonMagnets.CanBeBsonElements)org.mongodb.scala.bson.collection.immutable.Document <and>
(elems: org.mongodb.scala.bson.BsonMagnets.CanBeBsonElement*)org.mongodb.scala.bson.collection.immutable.Document <and>
(json: String)org.mongodb.scala.bson.collection.immutable.Document
cannot be applied to ((String, List[Map[String,String]]))
"$setOnInsert" -> Document(
I’ve already inserted String
and List[String]
elements without any issue, but can’t really figure out how to insert a List[Map[String, String]]
.
Which would be the way to insert a List[Map[String, String]]
so I can apply the attribute pattern via Scala?