Add DataFrame operationType=delete so Spark jobs can delete unmatched rows after a join

XMLWordPrintableJSON

    • Type: Improvement
    • Resolution: Unresolved
    • Priority: Unknown
    • None
    • Affects Version/s: None
    • Component/s: None
    • None
    • None
    • None
    • None
    • None
    • None
    • None

      Spark pipelines that keep MongoDB in sync with another dataset need to delete documents that fall out of a join. Today that is not possible through the connector write path.

      operationType is insert, replace, and update only. Replace/update upsert the matches and leave everyone else in the collection. overwrite drops the collection. Spark SQL DELETE FROM (SPARK-414) is a different API and does not take a DataFrame of ids from a join. Users are forced onto the Java driver.

      This should work:

      unmatched = mongo_df.join(other, "id", "left_anti")
      
      unmatched.select("_id").write.format("mongodb")
      .option("operationType", "delete").mode("append").save()
      

      Each row is a DeleteOneModel on idFieldList (default _id), same pattern as replace/update.

      Out of scope: SQL DELETE (SPARK-414 / SPARK-465), overwrite, UPDATE/MERGE.

      ross@mongodb.com I want to implement this. Is operationType=delete the right shape, or do you want this only via SQL DELETE?

            Assignee:
            Unassigned
            Reporter:
            David Dallakyan (EXT)
            None
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated: