Overview
Puedes configurar las siguientes propiedades cuando leas datos desde MongoDB en modo transmisión.
Nota
Si utilizas SparkConf Para establecer las configuraciones de lectura del conector, agregue el prefijo spark.mongodb.read. a cada propiedad.
Nombre de la propiedad | Descripción | ||
|---|---|---|---|
| Required. The connection string configuration key. Default: mongodb://localhost:27017/ | ||
| Required. The database name configuration. | ||
| Required. The collection name configuration. | ||
| The comment to append to the read operation. Comments appear in the
output of the Database Profiler. Default: None | ||
| MongoClientFactory configuration key. You can specify a custom implementation, which must implement the
com.mongodb.spark.sql.connector.connection.MongoClientFactory
interface.Default: com.mongodb.spark.sql.connector.connection.DefaultMongoClientFactory | ||
| Specifies a custom aggregation pipeline to apply to the collection
before sending data to Spark. The value must be either an extended JSON single document or list
of documents. A single document resembles the following: A list of documents resembles the following: Los pipelines de agregación personalizados deben ser compatibles con la estrategia de particionamiento. Por ejemplo, las etapas de agregación como | ||
| Specifies whether to allow storage to disk when running the
aggregation. Default: true | ||
| Change stream configuration prefix. See the
Change Stream Configuration section for more
information about change streams. | ||
| When true, the connector converts BSON types not supported by Spark into
extended JSON strings.
When false, the connector uses the original relaxed JSON format for
unsupported types.Default: false |
Cambiar la configuración del flujo
Puede configurar las siguientes propiedades al leer un flujo de cambios desde MongoDB:
Nombre de la propiedad | Descripción |
|---|---|
| Determina qué valores devuelve su flujo de cambios en las operaciones de actualización. La configuración predeterminada devuelve las diferencias entre el documento original y el documento actualizado. La configuración Para obtener más información sobre cómo funciona esta opción de flujo de cambios, consulte la guía del manual del servidor MongoDB Buscar documento completo para la operación de actualización. Predeterminado: "predeterminado" |
| The maximum number of partitions the Spark Connector divides each
micro-batch into. Spark workers can process these partitions in parallel. This setting applies only when using micro-batch streams. Default: 1ADVERTENCIA: Especificar un valor mayor que |
| Specifies whether to publish the changed document or the full
change stream document. When this setting is false, you must specify a schema. The schema
must include all fields that you want to read from the change stream. You can
use optional fields to ensure that the schema is valid for all change-stream
events.When this setting is true, the connector exhibits the following behavior:
Esta configuración anula la configuración Por defecto: |
| Specifies how the connector starts up when no offset is available. This setting accepts the following values:
|
Especificación de propiedades en connection.uri
Si utiliza SparkConf para especificar cualquiera de las configuraciones anteriores, puede incluirlas en la connection.uri configuración o enumerarlas individualmente.
El siguiente ejemplo de código muestra cómo especificar la base de datos, la colección y la preferencia de lectura como parte de la configuración connection.uri:
spark.mongodb.read.connection.uri=mongodb://127.0.0.1/myDB.myCollection?readPreference=primaryPreferred
Para mantener el connection.uri más breve y hacer que la configuración sea más fácil de leer, puedes especificarlos individualmente en su lugar:
spark.mongodb.read.connection.uri=mongodb://127.0.0.1/ spark.mongodb.read.database=myDB spark.mongodb.read.collection=myCollection spark.mongodb.read.readPreference.name=primaryPreferred
Importante
Si especifica una configuración tanto en la línea connection.uri como en la línea correspondiente, la configuración connection.uri tiene prioridad. Por ejemplo, en la siguiente configuración, la base de datos de conexión es foobar, porque es el valor de la configuración connection.uri:
spark.mongodb.read.connection.uri=mongodb://127.0.0.1/foobar spark.mongodb.read.database=bar