From bc608df0544d6a4868bbbceb5e8881f8e7d75f08 Mon Sep 17 00:00:00 2001
From: Vincent Beck <vincbeck@amazon.com>
Date: Mon, 28 Mar 2022 15:27:17 -0400
Subject: [PATCH 1/2] Add doc and sample dag for MongoToS3Operator

---
 .../aws/example_dags/example_mongo_to_s3.py   | 50 +++++++++++++++++
 .../amazon/aws/transfers/mongo_to_s3.py       |  4 ++
 airflow/providers/amazon/provider.yaml        |  1 +
 .../operators/transfer/dynamodb_to_s3.rst     |  4 +-
 .../operators/transfer/google_api_to_s3.rst   |  4 +-
 .../transfer/imap_attachment_to_s3.rst        |  4 +-
 .../operators/transfer/mongo_to_s3.rst        | 54 +++++++++++++++++++
 .../operators/transfer/redshift_to_s3.rst     |  4 +-
 .../operators/transfer/s3_to_redshift.rst     |  4 +-
 .../operators/transfer/salesforce_to_s3.rst   |  2 +-
 10 files changed, 120 insertions(+), 11 deletions(-)
 create mode 100644 airflow/providers/amazon/aws/example_dags/example_mongo_to_s3.py
 create mode 100644 docs/apache-airflow-providers-amazon/operators/transfer/mongo_to_s3.rst

diff --git a/airflow/providers/amazon/aws/example_dags/example_mongo_to_s3.py b/airflow/providers/amazon/aws/example_dags/example_mongo_to_s3.py
new file mode 100644
index 0000000000000..9c2d65bc5d40b
--- /dev/null
+++ b/airflow/providers/amazon/aws/example_dags/example_mongo_to_s3.py
@@ -0,0 +1,50 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+
+import os
+
+from airflow import models
+from airflow.providers.amazon.aws.transfers.mongo_to_s3 import MongoToS3Operator
+from airflow.utils.dates import datetime
+
+S3_BUCKET = os.environ.get("S3_BUCKET", "test-bucket")
+S3_KEY = os.environ.get("S3_KEY", "key")
+MONGO_DATABASE = os.environ.get("MONGO_DATABASE", "Test")
+MONGO_COLLECTION = os.environ.get("MONGO_COLLECTION", "Test")
+
+with models.DAG(
+    "example_mongo_to_s3",
+    schedule_interval=None,
+    start_date=datetime(2021, 1, 1),
+    catchup=False,
+) as dag:
+    # [START howto_transfer_mongo_to_s3]
+    create_local_to_s3_job = MongoToS3Operator(
+        task_id="create_mongo_to_s3_job",
+        mongo_collection=MONGO_COLLECTION,
+        # Mongo query by matching values
+        # Here returns all documents which have "OK" as value for the key "status"
+        mongo_query={
+            "status": "OK"
+        },
+        s3_bucket=S3_BUCKET,
+        s3_key=S3_KEY,
+        mongo_db=MONGO_DATABASE,
+        replace=True,
+    )
+    # [END howto_transfer_mongo_to_s3]
diff --git a/airflow/providers/amazon/aws/transfers/mongo_to_s3.py b/airflow/providers/amazon/aws/transfers/mongo_to_s3.py
index 218d35c892b96..44aae36378a29 100644
--- a/airflow/providers/amazon/aws/transfers/mongo_to_s3.py
+++ b/airflow/providers/amazon/aws/transfers/mongo_to_s3.py
@@ -37,6 +37,10 @@
 class MongoToS3Operator(BaseOperator):
     """Operator meant to move data from mongo via pymongo to s3 via boto.
 
+    .. seealso::
+        For more information on how to use this operator, take a look at the guide:
+        :ref:`howto/operator:MongoToS3Operator`
+
     :param mongo_conn_id: reference to a specific mongo connection
     :param aws_conn_id: reference to a specific S3 connection
     :param mongo_collection: reference to a specific collection in your mongo db
diff --git a/airflow/providers/amazon/provider.yaml b/airflow/providers/amazon/provider.yaml
index aeaf630105ce7..deaf18b085082 100644
--- a/airflow/providers/amazon/provider.yaml
+++ b/airflow/providers/amazon/provider.yaml
@@ -472,6 +472,7 @@ transfers:
     python-module: airflow.providers.amazon.aws.transfers.imap_attachment_to_s3
   - source-integration-name: MongoDB
     target-integration-name: Amazon Simple Storage Service (S3)
+    how-to-guide: /docs/apache-airflow-providers-amazon/operators/transfer/mongo_to_s3.rst
     python-module: airflow.providers.amazon.aws.transfers.mongo_to_s3
   - source-integration-name: MySQL
     target-integration-name: Amazon Simple Storage Service (S3)
diff --git a/docs/apache-airflow-providers-amazon/operators/transfer/dynamodb_to_s3.rst b/docs/apache-airflow-providers-amazon/operators/transfer/dynamodb_to_s3.rst
index 6ecc063e4b090..2fad595e81c5b 100644
--- a/docs/apache-airflow-providers-amazon/operators/transfer/dynamodb_to_s3.rst
+++ b/docs/apache-airflow-providers-amazon/operators/transfer/dynamodb_to_s3.rst
@@ -16,8 +16,8 @@
     under the License.
 
 
-Amazon DynamoDB to S3 Transfer Operator
-=======================================
+Amazon DynamoDB to Amazon S3 Transfer Operator
+==============================================
 
 Use the DynamoDBToS3Operator transfer to copy the contents of an existing Amazon DynamoDB table
 to an existing Amazon Simple Storage Service (S3) bucket.
diff --git a/docs/apache-airflow-providers-amazon/operators/transfer/google_api_to_s3.rst b/docs/apache-airflow-providers-amazon/operators/transfer/google_api_to_s3.rst
index 87e72c96052e2..7e5ddaae9868e 100644
--- a/docs/apache-airflow-providers-amazon/operators/transfer/google_api_to_s3.rst
+++ b/docs/apache-airflow-providers-amazon/operators/transfer/google_api_to_s3.rst
@@ -16,8 +16,8 @@
     specific language governing permissions and limitations
     under the License.
 
-Google API To Amazon S3 Operator
-================================
+Google API to Amazon S3 Transfer Operator
+=========================================
 
 Use the GoogleApiToS3Transfer transfer to call requests to any Google API which supports discovery and save its response
 on Amazon S3.
diff --git a/docs/apache-airflow-providers-amazon/operators/transfer/imap_attachment_to_s3.rst b/docs/apache-airflow-providers-amazon/operators/transfer/imap_attachment_to_s3.rst
index f63ae67177d0e..2e9b6a758f10f 100644
--- a/docs/apache-airflow-providers-amazon/operators/transfer/imap_attachment_to_s3.rst
+++ b/docs/apache-airflow-providers-amazon/operators/transfer/imap_attachment_to_s3.rst
@@ -15,8 +15,8 @@
     specific language governing permissions and limitations
     under the License.
 
-Imap Attachment To Amazon S3 Operator
-=====================================
+Imap Attachment to Amazon S3 Transfer Operator
+==============================================
 
 The ``ImapAttachmentToS3Operator`` transfers an email attachment via IMAP
 protocol from a mail server to an Amazon S3 Bucket.
diff --git a/docs/apache-airflow-providers-amazon/operators/transfer/mongo_to_s3.rst b/docs/apache-airflow-providers-amazon/operators/transfer/mongo_to_s3.rst
new file mode 100644
index 0000000000000..209461f5be57c
--- /dev/null
+++ b/docs/apache-airflow-providers-amazon/operators/transfer/mongo_to_s3.rst
@@ -0,0 +1,54 @@
+ .. Licensed to the Apache Software Foundation (ASF) under one
+    or more contributor license agreements.  See the NOTICE file
+    distributed with this work for additional information
+    regarding copyright ownership.  The ASF licenses this file
+    to you under the Apache License, Version 2.0 (the
+    "License"); you may not use this file except in compliance
+    with the License.  You may obtain a copy of the License at
+
+ ..   http://www.apache.org/licenses/LICENSE-2.0
+
+ .. Unless required by applicable law or agreed to in writing,
+    software distributed under the License is distributed on an
+    "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+    KIND, either express or implied.  See the License for the
+    specific language governing permissions and limitations
+    under the License.
+
+MongoDB to Amazon S3 Transfer Operator
+======================================
+
+Use the MongoToS3Operator transfer to copy data from a MongoDB collection into an Amazon Simple Storage Service (S3) file.
+
+Prerequisite Tasks
+^^^^^^^^^^^^^^^^^^
+
+.. include:: ../_partials/prerequisite_tasks.rst
+
+.. _howto/operator:MongoToS3Operator:
+
+MongoDB To Amazon S3
+^^^^^^^^^^^^^^^^^^^^
+
+This operator copies a set of data from a MongoDB collection to an Amazon S3 files.
+In order to select the data you want to copy, you need to use the ``mongo_query`` parameter.
+
+To get more information about this operator visit:
+:class:`~airflow.providers.amazon.aws.transfers.mongo_to_s3.MongoToS3Operator`
+
+Example usage:
+
+.. exampleinclude:: /../../airflow/providers/amazon/aws/example_dags/example_mongo_to_s3.py
+    :language: python
+    :dedent: 4
+    :start-after: [START howto_transfer_mongo_to_s3]
+    :end-before: [END howto_transfer_mongo_to_s3]
+
+You can find more information about ``PyMongo`` used by Airflow to communicate with MongoDB
+`here <https://pymongo.readthedocs.io/en/stable/tutorial.html>`__.
+
+Reference
+^^^^^^^^^
+
+* `PyMongo <https://pymongo.readthedocs.io/en/stable/tutorial.html>`__
+* `AWS boto3 Library Documentation for Amazon S3 <https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/s3.html>`__
diff --git a/docs/apache-airflow-providers-amazon/operators/transfer/redshift_to_s3.rst b/docs/apache-airflow-providers-amazon/operators/transfer/redshift_to_s3.rst
index 64a7d2dadda83..72306a89a0995 100644
--- a/docs/apache-airflow-providers-amazon/operators/transfer/redshift_to_s3.rst
+++ b/docs/apache-airflow-providers-amazon/operators/transfer/redshift_to_s3.rst
@@ -15,8 +15,8 @@
     specific language governing permissions and limitations
     under the License.
 
-Amazon Redshift to S3 Transfer Operator
-=======================================
+Amazon Redshift to Amazon S3 Transfer Operator
+==============================================
 
 Use the RedshiftToS3Operator transfer to copy the data from an Amazon Redshift table into an Amazon Simple Storage
 Service (S3) file.
diff --git a/docs/apache-airflow-providers-amazon/operators/transfer/s3_to_redshift.rst b/docs/apache-airflow-providers-amazon/operators/transfer/s3_to_redshift.rst
index 1a686ad913a6d..877e7dde594eb 100644
--- a/docs/apache-airflow-providers-amazon/operators/transfer/s3_to_redshift.rst
+++ b/docs/apache-airflow-providers-amazon/operators/transfer/s3_to_redshift.rst
@@ -15,8 +15,8 @@
     specific language governing permissions and limitations
     under the License.
 
-Amazon S3 to Redshift Transfer Operator
-=======================================
+Amazon S3 to Amazon Redshift Transfer Operator
+==============================================
 
 Use the S3ToRedshiftOperator transfer to copy the data from an Amazon Simple Storage Service (S3) file into an
 Amazon Redshift table.
diff --git a/docs/apache-airflow-providers-amazon/operators/transfer/salesforce_to_s3.rst b/docs/apache-airflow-providers-amazon/operators/transfer/salesforce_to_s3.rst
index 0b6e0374c3e9c..06bd1bb4e7de3 100644
--- a/docs/apache-airflow-providers-amazon/operators/transfer/salesforce_to_s3.rst
+++ b/docs/apache-airflow-providers-amazon/operators/transfer/salesforce_to_s3.rst
@@ -15,7 +15,7 @@
     specific language governing permissions and limitations
     under the License.
 
-Salesforce To Amazon S3 Transfer Operator
+Salesforce to Amazon S3 Transfer Operator
 =========================================
 
 Use the

From 8e1313a1b7e7ed3b13d991cdeff526f807927763 Mon Sep 17 00:00:00 2001
From: Vincent Beck <vincbeck@amazon.com>
Date: Tue, 29 Mar 2022 13:06:16 -0400
Subject: [PATCH 2/2] Fix static checks

---
 .../providers/amazon/aws/example_dags/example_mongo_to_s3.py  | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/airflow/providers/amazon/aws/example_dags/example_mongo_to_s3.py b/airflow/providers/amazon/aws/example_dags/example_mongo_to_s3.py
index 9c2d65bc5d40b..e95964b59cee1 100644
--- a/airflow/providers/amazon/aws/example_dags/example_mongo_to_s3.py
+++ b/airflow/providers/amazon/aws/example_dags/example_mongo_to_s3.py
@@ -39,9 +39,7 @@
         mongo_collection=MONGO_COLLECTION,
         # Mongo query by matching values
         # Here returns all documents which have "OK" as value for the key "status"
-        mongo_query={
-            "status": "OK"
-        },
+        mongo_query={"status": "OK"},
         s3_bucket=S3_BUCKET,
         s3_key=S3_KEY,
         mongo_db=MONGO_DATABASE,
