filterPosOp support
We need to support filterPosOp (.$[<identifier>].) in a convenient manner.
Example with KMongo:
data class Parent(val _id: String, val list: List<Element>)
data class Element(val id: String, val value: String)
override fun updateListElements(objectId: String, elements: List<Element>) {
val setBsons = mutableListOf<Bson>()
val arrayFilters = mutableListOf<Bson>()
elements.filter { !it.id.isNullOrBlank() }
.forEachIndexed { index, element ->
setBsons.add(
Updates.set("${Parent::list.path()}.\$[elem${index}id]", element)
)
arrayFilters.add(
"{'elem${index}id': '${element.id}'}".bson
)
}
col.updateOne(Parent::_id eq ObjectId(objectId), combine(setBsons), UpdateOptions().arrayFilters(arrayFilters))
}
Edited by Ivan “CLOVIS” Canet