Skip to main content

Singer.io tap for extracting data from MongoDB - Datazip compatible

Project description

sh-mongodb

This is a Singer tap that produces JSON-formatted data following the Singer spec from a MongoDB source.

Set up local dev environment:

make setup

Activate virtual environment

. venv/bin/activate

Set up Config file

Create json file called config.json, with the following contents:

{
  "password": "<password>",
  "user": "<username>",
  "host": "<host ip address>",
  "auth_database": "<database name to authenticate on>",
  "database": "<database name to sync from>"
}

The following parameters are optional for your config file:

Name Type Default value Description
srv Boolean false uses a mongodb+srv protocol to connect. Disables the usage of port argument if set to True
port Integer false Connection port. Required if a non-srv connection is being used.
replica_set string null name of replica set
ssl Boolean false can be set to true to connect using ssl
verify_mode Boolean true Default SSL verify mode
include_schemas_in_destination_stream_name Boolean false forces the stream names to take the form <database_name>-<collection_name> instead of <collection_name>
update_buffer_size int 1 [LOG_BASED] The size of the buffer that holds detected update operations in memory, the buffer is flushed once the size is reached
await_time_ms int 1000 [LOG_BASED] The maximum amount of time in milliseconds the loge_base method waits for new data changes before exiting.
full_load_on_empty_state bool false [LOG_BASED] A flag which forces full load when no previous token is found in state.

All of the above attributes are required by the tap to connect to your mongo instance. here is a sample configuration file.

Run in discovery mode

Run the following command and redirect the output into the catalog file

sh-mongodb --config ~/config.json --discover > ~/catalog.json

Your catalog file should now look like this:

{
  "streams": [
    {
      "table_name": "<table name>",
      "tap_stream_id": "<tap_stream_id>",
      "metadata": [
        {
          "breadcrumb": [],
          "metadata": {
            "row-count":<int>,
            "is-view": <bool>,
            "database-name": "<database name>",
            "table-key-properties": [
              "_id"
            ],
            "valid-replication-keys": [
              "_id"
            ]
          }
        }
      ],
      "stream": "<stream name>",
      "schema": {
        "type": "object"
      }
    }
  ]
}

Edit Catalog file

Using valid json, edit the config.json file

To select a stream, enter the following to the stream's metadata:

"selected": true,
"replication-method": "<replication method>",

<replication-method> must be either FULL_TABLE, INCREMENTAL or LOG_BASED, if it's INCREMENTAL, make sure to add a "replication-key".

For example, if you were to edit the example stream to select the stream as well as add a projection, config.json should look this:

{
  "streams": [
    {
      "table_name": "<table name>",
      "tap_stream_id": "<tap_stream_id>",
      "metadata": [
        {
          "breadcrumb": [],
          "metadata": {
            "row-count": <int>,
            "is-view": <bool>,
            "database-name": "<database name>",
            "table-key-properties": [
              "_id"
            ],
            "valid-replication-keys": [
              "_id"
            ],
            "selected": true,
            "replication-method": "<replication method>"
          }
        }
      ],
      "stream": "<stream name>",
      "schema": {
        "type": "object"
      }
    }
  ]
}

Run in sync mode:

sh-mongodb --config ~/config.json --catalog ~/catalog.json

The tap will write bookmarks to stdout which can be captured and passed as an optional --state state.json parameter to the tap for the next sync.

Logging configuration

The tap uses a predefined logging config if none is provided, however, you can set your own config by setting the environment variable LOGGING_CONFIG_FILE as the path to the logging config. A sample config is available here.


Copyright © 2020 TransferWise

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

sh-mongodb-1.0.1.tar.gz (30.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

sh_mongodb-1.0.1-py3-none-any.whl (51.7 kB view details)

Uploaded Python 3

File details

Details for the file sh-mongodb-1.0.1.tar.gz.

File metadata

  • Download URL: sh-mongodb-1.0.1.tar.gz
  • Upload date:
  • Size: 30.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.9.6

File hashes

Hashes for sh-mongodb-1.0.1.tar.gz
Algorithm Hash digest
SHA256 700d00064144ef4726759b504a11c7726ad23e0e1db180d387efe0c8b1098e3c
MD5 a6b93b22e0bca23b7d79ecf2be38d427
BLAKE2b-256 d2a777f7fd4e52975118877b66312838f2b4a6c0af83c5be58db5edb889f024d

See more details on using hashes here.

File details

Details for the file sh_mongodb-1.0.1-py3-none-any.whl.

File metadata

  • Download URL: sh_mongodb-1.0.1-py3-none-any.whl
  • Upload date:
  • Size: 51.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.9.6

File hashes

Hashes for sh_mongodb-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 931161e762409ec98de771e65f855d6d28a2e23882152ba79f92b006085be7ae
MD5 eba58e1b78b8bfbf9b42e3cb946d2ffb
BLAKE2b-256 e4579ff81107557d806408c93d0245aeccf7c616de072e8eda79bb73eccb3f60

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page