我正在尝试使用scala和reactive mongo更新嵌套列表中的元素。我试过这个:
def updatethirdList(secondListElementId: UUID, firstObject: FirstObject): Future[Either[String, UUID]] = {
val query = Json.obj("secondList.thirdList._id" -> secondListElementId)
val update = Json.obj("$set" -> Json.obj("secondList.$.thirdList" -> sessionType))
collection.update(query, update).map {
case result if result.ok == true => Right(secondListElementId)
case result => Left(result.message)
}
}
结构:
{
"firstList":[{
"secondList":[{
"thirdList":[{
"firstObject":""
}]
}]
}]
}
我的代码的问题是它给出了这个结果: firstList.0.secondList.0.thirdList = firstObject 它应该举例如下: firstList.0.secondList.0.thirdList.0 = firstObject
我试过了:
val update = Json.obj("$set" -> Json.obj("secondList.$.thirdList.$" -> firstObject))
但我收到此错误:MongoDB:在路径中找到太多位置(即'$')元素
请帮助