Visão geral
Você pode configurar as seguintes propriedades ao ler dados do MongoDB no modo de streaming.
Observação
Se você usa o SparkConf
para definir as configurações de leitura do conector, insira spark.mongodb.read.
como prefixo em cada propriedade.
Nome da propriedade | Descrição | ||
---|---|---|---|
| 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:
Pipelines de agregação personalizados devem ser compatíveis com a estratégia do particionador. Por exemplo, estágios de agregação 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 |
Alterar configuração do stream
Você pode configurar as seguintes propriedades ao ler um change stream do MongoDB:
Nome da propriedade | Descrição |
---|---|
| Determina quais valores seu change stream retorna nas operações de atualização. A configuração padrão retorna as diferenças entre o documento original e o documento atualizado. A configuração Para obter mais informações sobre como essa opção de fluxo de alterações funciona, consulte o guia manual do servidor MongoDB Pesquisar documento completo para operação de atualização. Padrão: "default" |
| 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: 1 AVISO: especificar um valor superior a |
| 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 configuração substitui a configuração Padrão: |
| Specifies how the connector starts up when no offset is available. This setting accepts the following values:
|
Especificando propriedades em connection.uri
Se você usa SparkConf para especificar qualquer uma das configurações anteriores, você poderá incluí-las na configuração do connection.uri
ou listá-las individualmente.
O exemplo de código abaixo mostra como especificar o banco de dados, coleção e preferência de leitura como parte da configuração do connection.uri
:
spark.mongodb.read.connection.uri=mongodb://127.0.0.1/myDB.myCollection?readPreference=primaryPreferred
Para manter o connection.uri
curto e facilitar a leitura das configurações, você pode especificá-las individualmente:
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
Se você especificar uma configuração em connection.uri
e em sua própria linha, a configuração connection.uri
terá precedência. Por exemplo, na configuração abaixo, o banco de dados de conexão é foobar
, porque é o valor na configuração connection.uri
:
spark.mongodb.read.connection.uri=mongodb://127.0.0.1/foobar spark.mongodb.read.database=bar