@@ -92,6 +92,61 @@ Configuring a Write Stream to MongoDB
92
92
For a complete list of methods, see the
93
93
`pyspark Structured Streaming reference <https://spark.apache.org/docs/latest/api/python/reference/pyspark.ss.html>`__.
94
94
95
+ - id: scala
96
+ content: |
97
+
98
+ Specify write stream configuration settings on your streaming
99
+ Dataset or DataFrame using the ``writeStream`` property. You
100
+ must specify the following configuration settings to write
101
+ to MongoDB:
102
+
103
+ .. list-table::
104
+ :header-rows: 1
105
+ :stub-columns: 1
106
+ :widths: 10 40
107
+
108
+ * - Setting
109
+ - Description
110
+
111
+ * - ``writeStream.format()``
112
+ - The format to use for write stream data. Use
113
+ ``mongodb``.
114
+
115
+ * - ``writeStream.option()``
116
+ - Use the ``option`` method to specify your MongoDB
117
+ deployment connection string with the
118
+ ``spark.mongodb.connection.uri`` option key.
119
+
120
+ You must specify a database and collection, either as
121
+ part of your connection string or with additional
122
+ ``option`` methods using the following keys:
123
+
124
+ - ``spark.mongodb.database``
125
+ - ``spark.mongodb.collection``
126
+
127
+ * - ``writeStream.outputMode()``
128
+ - The output mode to use. To view a list of all supported
129
+ output modes, see `the pyspark outputMode documentation <https://spark.apache.org/docs/latest/api/python/reference/api/pyspark.sql.streaming.DataStreamWriter.outputMode.html#pyspark.sql.streaming.DataStreamWriter.outputMode>`__.
130
+
131
+
132
+ The following code snippet shows how to use the preceding
133
+ configuration settings to stream data to MongoDB:
134
+
135
+ .. code-block:: python
136
+ :copyable: true
137
+ :emphasize-lines: 3-4, 7
138
+
139
+ <streaming Dataset/ DataFrame> \
140
+ .writeStream \
141
+ .format("mongodb") \
142
+ .option("spark.mongodb.connection.uri", <mongodb-connection-string>) \
143
+ .option("spark.mongodb.database", <database-name>) \
144
+ .option("spark.mongodb.collection", <collection-name>) \
145
+ .outputMode("append")
146
+
147
+ For a complete list of methods, see the
148
+ `pyspark Structured Streaming reference <https://spark.apache.org/docs/latest/api/python/reference/pyspark.ss.html>`__.
149
+
95
150
.. _read-structured-stream:
96
151
.. _continuous-processing:
97
152
0 commit comments