1

I'm trying to update an element in nested lists with scala and reactive mongo. I tried this:

  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)
    }
  }

the structure:

{
"firstList":[{
            "secondList":[{
                         "thirdList":[{
                                     "firstObject":""
                                     }]
                         }]
            }]
}

the problem with my code is that it's gave this result: firstList.0.secondList.0.thirdList = firstObject it should give for example this : firstList.0.secondList.0.thirdList.0 = firstObject

I tried this:

val update = Json.obj("$set" -> Json.obj("secondList.$.thirdList.$" -> firstObject))

but I get this error: MongoDB: Too many positional (i.e. '$') elements found in path

Any help please

Rajeun
  • 721
  • 2
  • 12
  • 37

0 Answers0