Overview
You can configure the following properties when writing data to MongoDB in batch mode.
Note
If you use SparkConf to set the connector's write configurations, prefix spark.mongodb.write. to each property.
Property name | Description | |
|---|---|---|
| Required. | |
| Required. | |
| Required. | |
| The comment to append to the write operation. Comments appear in the
output of the Database Profiler. | |
| MongoClientFactory configuration key. | |
| Specifies if the connector parses string values and converts extended JSON
into BSON.
Default: | |
| Specifies a field or list of fields by which to split the collection data. To specify more than one field, separate them using a comma as shown in the following example: Default: | |
| When | |
| Specifies the maximum number of operations to batch in bulk
operations. | |
| Specifies the type of write operation to perform. You can set this to one of the following values:
| |
| Specifies whether to perform ordered bulk operations. | |
| When | |
| Specifies | |
| Specifies | |
| Specifies | |
| Specifies how to truncate a collection when performing an overwrite. You can set this option to one of the following values:
| |
| When set to |
Specifying Properties in connection.uri
If you use SparkConf to specify any of the previous settings, you can either include them in the connection.uri setting or list them individually.
The following code example shows how to specify the database, collection, and convertJson setting as part of the connection.uri setting:
spark.mongodb.write.connection.uri=mongodb://127.0.0.1/myDB.myCollection?convertJson=any
To keep the connection.uri shorter and make the settings easier to read, you can specify them individually instead:
spark.mongodb.write.connection.uri=mongodb://127.0.0.1/ spark.mongodb.write.database=myDB spark.mongodb.write.collection=myCollection spark.mongodb.write.convertJson=any
Important
If you specify a setting in both the connection.uri and on its own line, the connection.uri setting takes precedence. For example, in the following configuration, the connection database is foobar:
spark.mongodb.write.connection.uri=mongodb://127.0.0.1/foobar spark.mongodb.write.database=bar