Skip to content

MongoDB

Bases: Spout

__init__(output, state, **kwargs)

Initialize the MongoDB class.

Parameters:

Name Type Description Default
output BatchOutput

An instance of the BatchOutput class for saving the data.

required
state State

An instance of the State class for maintaining the state.

required
**kwargs

Additional keyword arguments.

{}

Using geniusrise to invoke via command line

genius MongoDB rise \
    batch \
        --output_s3_bucket my_bucket \
        --output_s3_folder s3/folder \
    none \
    fetch \
        --args host=localhost port=27017 username=myusername password=mypassword database=mydatabase collection=mycollection

Using geniusrise to invoke via YAML file

version: "1"
spouts:
    my_mongodb_spout:
        name: "MongoDB"
        method: "fetch"
        args:
            host: "localhost"
            port: 27017
            username: "myusername"
            password: "mypassword"
            database: "mydatabase"
            collection: "mycollection"
        output:
            type: "batch"
            args:
                bucket: "my_bucket"
                s3_folder: "s3/folder"

fetch(host, port, username, password, database, collection)

📖 Fetch data from a MongoDB database and save it in batch.

Parameters:

Name Type Description Default
host str

The MongoDB host.

required
port int

The MongoDB port.

required
username str

The MongoDB username.

required
password str

The MongoDB password.

required
database str

The MongoDB database name.

required
collection str

The MongoDB collection name.

required

Raises:

Type Description
Exception

If unable to connect to the MongoDB server or execute the query.