使用 MongoDB 或 MongoDB Atlas 连接
为 MongoDB 或 MongoDB Atlas 创建连接后,您可以在 ETL 作业中使用该连接。您可以在 Amazon Glue Data Catalog 中创建一个表,并为该表的 connection
属性指定 MongoDB Atlas 连接。
Amazon Glue 在 MongoDB 连接中存储您的连接 url
和凭证。连接 URI 格式如下:
对于 MongoDB:mongodb://host:port/database。主机可以是主机名、IP 地址或 UNIX 域套接字。如果连接字符串未指定端口,则使用默认的 MongoDB 端口 27017。
对于 MongoDB Atlas:mongodb+srv://server.example.com/database。主机可以是后面对应于 DNS SRV 记录的主机名。SRV 格式不需要端口,将使用默认的 MongoDB 端口 27017。
此外,您可以在作业脚本中指定以下选项。
-
"database"
:(必需)要从中读取数据的 MongoDB 数据库。 -
"collection"
:(必需)要从中读取数据的 MongoDB 集合。 -
"ssl"
:[可供(选择)]如果为true
,则 Amazon Glue 发起 SSL 连接。默认值为false
。 -
"ssl.domain_match"
:(可选)如果为true
,且ssl
为true
,则 Amazon Glue 执行域匹配检查。默认值为true
。 -
"batchSize"
:(可选)每个批处理返回的文档数量,在内部批处理的游标中使用。 -
"partitioner"
:(可选)从 MongoDB 中读取输入数据的分区器的类名称。该连接器提供以下分区器:-
MongoDefaultPartitioner
(默认值) -
MongoSamplePartitioner
(需要 MongoDB 3.2 或更高版本) -
MongoShardedPartitioner
-
MongoSplitVectorPartitioner
-
MongoPaginateByCountPartitioner
-
MongoPaginateBySizePartitioner
-
-
"partitionerOptions"
:(可选)指定分区器的选项。各个分区器支持的选项如下:-
MongoSamplePartitioner
–partitionKey
、partitionSizeMB
和samplesPerPartition
-
MongoShardedPartitioner
–shardkey
-
MongoSplitVectorPartitioner
–partitionKey
和partitionSizeMB
-
MongoPaginateByCountPartitioner
–partitionKey
和numberOfPartitions
-
MongoPaginateBySizePartitioner
–partitionKey
和partitionSizeMB
-
有关这些选项的详细信息,请参阅 https://docs.mongodb.com/spark-connector/master/configuration/#partitioner-conf