写入MongoDB副本集时出现MongoSpark E11000错误

写入MongoDB副本集时出现MongoSpark E11000错误,mongodb,scala,apache-spark,replicaset,Mongodb,Scala,Apache Spark,Replicaset,我正在使用一个Spark2应用程序,该应用程序使用com.mongodb.spark.MongoSpark中的以下命令将数据帧写入三节点mongodb副本集: //The real command is similar to this one, depending on options //set to the DataFrame and the DataFrameWriter object about MongoDB configurations, //such as the

我正在使用一个Spark2应用程序,该应用程序使用com.mongodb.spark.MongoSpark中的以下命令将数据帧写入三节点mongodb副本集

    //The real command is similar to this one, depending on options
    //set to the DataFrame and the DataFrameWriter object about MongoDB configurations,
 //such as the writeConcern

    var df: DataFrameWriter[Row] = spark.sql(sql).write
              .option("uri", theUri)
              .option("database", theDatabase)
              .option("collection", theCollection)
              .option("replaceDocument", "false")
              .mode("append")
            [...]    
            MongoSpark.save(df)
事实上,尽管我确信源数据(来自配置单元表)具有唯一主键,但当Spark应用程序运行时,我得到一个重复键错误:

2019-01-14 13:01:08 ERROR: Job aborted due to stage failure: Task 51 in stage 19.0 failed 8 times,
     most recent failure: Lost task 51.7 in stage 19.0 (TID 762, mymachine, executor 21): 
com.mongodb.MongoBulkWriteException: Bulk write operation error on server myserver. 
Write errors: [BulkWriteError{index=0, code=11000,
message='E11000 duplicate key error collection: 
    ddbb.tmp_TABLE_190114125615 index: idx_unique dup key: { : "00120345678" }', details={ }}]. 
at com.mongodb.connection.BulkWriteBatchCombiner.getError(BulkWriteBatchCombiner.java:176)
at com.mongodb.connection.BulkWriteBatchCombiner.throwOnError(BulkWriteBatchCombiner.java:205)
[...]
我曾尝试将“关注事项”设置为“3”甚至“多数”。此外,超时已设置为4/5秒,但有时仍会出现此重复键错误

我想知道如何配置负载,以便在写入副本集时不获得重复条目


有什么建议吗?提前谢谢

产生dup密钥错误的文档来自哪里?
idx\u unqiue
是否应用于正确的字段?idx\u unique是在一个字段上创建的,该字段是从配置单元表中的四个字段计算而来的:选择CONCAT(字段1、字段2、字段3、字段4)作为idUnique。然后,已经实现了一个检测重复项的过程,所以我确信,我肯定应该在MongoDB中编写唯一的条目。但是,似乎在写入过程中进行了写入,然后执行了重试—文档已存储在集合中—因此引发了异常。当前使用的依赖项:>org.mongodb.spark mongo-spark-connector_2.11 2.2.5I没有通过使用唯一字符串(例如,concat表主键字段的值)作为每个文档的_id再次看到此错误