Skip to main content

A mongodb aggregate export tool

Project description

maggport

Coverage Report pre-commit security: bandit Imports: isort Code style: black

A mongodb aggregate export CLI tool

Overview

maggport is a python CLI tool designed to bridge the gap of exporting aggregate pipeline(s) in mongodb. What used to be a feat accomplished by writing your own shell script or exporting a custom mongodb collection to csv, txt, or JSON, generated by running an aggregate pipeline, can now be achieved by this tool.

Installation

pip install maggport

Usage

Arguments Description
-c/--collection Collection of database
-d/--db Database to connect
--header Export with header
-h/--host Hostname of mongodb instance
--no-allow-disk-use Don't allow disk use
-o/--out Output file
-p/--port Port of mongodb instance
-q/--pipeline Pipeline to run
-f/--pipeline-path Path of pipeline if saved in file

host: sample_host
port: 8080
db: food
collection: fruits

[
    {
        "name": "apple",
        "origin":  "usa",
        "price": 5
    },
    {
        "name": "apple",
        "origin":  "italy",
        "price": 4
    },
    {
        "name": "apple",
        "origin":  "philippines",
        "price": 3
    },
    {
        "name": "mango",
        "origin":  "malaysia",
        "price": 3
    }
]

Example 1

Passing pipeline as a parameter and output results in terminal.

maggport --host sample_host --port 8080 --db food --collection fruits --pipeline '[{"$group": {"_id": "$name", "count": {"$sum": 1}}}, {"$match": {"count": {"$gt": 1}}}]'

Output:

[
    {
        "_id":"apple",
        "count": 3
    }
]

Example 2

Passing pipeline as a file and output results in terminal.

pipeline.txt

[
    {"$group": {"_id": "$name", "count": {"$sum": 1}}},
    {"$match": {"count": {"$gt": 1}}}
]
maggport --host sample_host --port 8080 --db food --collection fruits --pipeline-path pipeline.txt

Output:

[
    {
        "_id":"apple",
        "count": 3
    }
]

Example 3

Export results as csv file.

pipeline.txt

[
    {"$group": {"_id": "$name", "count": {"$sum": 1}}},
    {"$match": {"count": {"$gt": 1}}}
]
maggport --host sample_host --port 8080 --db food --collection fruits --pipeline-path pipeline.txt --out test_results.csv

Output:

test_results.csv

image

Bugs/Request

Please submit an issue in GitHub

Contributing

When contributing to this repository, please first discuss the change you wish to make via issue in the maggport dashboard, or any other method with the owner(s)(info at the bottom of this README) of this repository before making a change.

Please note we have a code of conduct, please follow it in all your interactions with the project.

For more information about how to contribute, take a look at CONTRIBUTE.md

Our Responsibilities

Project maintainers are responsible for clarifying the standards of acceptable behavior and are expected to take appropriate and fair corrective action in response to any instances of unacceptable behavior.

Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, or to ban temporarily or permanently any contributor for other behaviors that they deem inappropriate, threatening, offensive, or harmful.

Attribution

This Code of Conduct is adapted from the Contributor Covenant, version 1.4, available at http://contributor-covenant.org/version/1/4

Maintainers

@ccavales3

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

maggport-1.0.4.tar.gz (7.0 kB view hashes)

Uploaded Source

Built Distributions

maggport-1.0.4-py3.9.egg (11.5 kB view hashes)

Uploaded Source

maggport-1.0.4-py3-none-any.whl (7.5 kB view hashes)

Uploaded Python 3

Supported by

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