我正在使用Spark-MongoDB和我试图保存一个数据框架到MongoDB:
val event = """{"Dev":[{"a":3},{"b":3}],"hr":[{"a":6}]}"""
val events = sc.parallelize(event :: Nil)
val df = sqlc.read.json(events)
val saveConfig = MongodbConfigBuilder(Map(Host -> List("localhost:27017"),
Database -> "test", Collection -> "test", SamplingRatio -> 1.0, WriteConcern -> "normal",
SplitSize -> 8, SplitKey -> "_id"))
df.saveToMongodb(saveConfig.build)
我希望数据被保存为输入字符串,但实际保存的是:
{" _id ": ObjectId (" 57 cedf4bd244c56e8e783a45 "),"开发":[{"a":NumberLong(3),"b":零},{"a":零,"b":NumberLong(3)}),"人力资源":[{"a":NumberLong (6)}]}
我想避免那些空值和重复,有什么想法吗?
您是否尝试过使用反斜杠定义如下事件:
val event = "{"Dev":[{"a":3},{"b":3}],"hr":[{"a":6}]}"