-1

Been recently trying to compress within a single Map all the values that will go within my $set clause when performing an upsert to MongoDB.

However, this was previously done with a single typed Map[String, Long] which worked. However, since I know that $set may contain (and does) different types I wanted to put in there multiple fields that I do need in the $set clause.

I've tried the following without any success.

                  "$set" -> Document(
                    item.getAs[Map[String, _]]("mapField")
                  )

This complains already in the IDE with Cannot resolve overloaded method Document.

Is there any way to accomplish this without using the ++ operator and thus having more columsn spread accross the DataFrame?

czr_RR
  • 541
  • 5
  • 16

1 Answers1

0

Scala Map is not the same as a Java Map and you forgot about new word before Document. Document constructor expects Java map but you tries to pass the scala map. I think you need to convert scala map to java map:

import scala.collection.JavaConversions._
"$set" -> new Document(
  mapAsJavaMap(item.getAs[Map[String, Object]]("mapField"))
)
Boris Azanov
  • 4,408
  • 1
  • 15
  • 28