{"id":29267131,"url":"https://github.com/vianneymi/monggregate","last_synced_at":"2025-07-30T18:07:09.508Z","repository":{"id":62326825,"uuid":"536755358","full_name":"VianneyMI/monggregate","owner":"VianneyMI","description":"Library to make MongoDB aggregation framework and pipelines easy to use in python.","archived":false,"fork":false,"pushed_at":"2025-06-25T21:47:27.000Z","size":1754,"stargazers_count":21,"open_issues_count":41,"forks_count":4,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-07-04T17:13:06.848Z","etag":null,"topics":["aggregation-framework","aggregation-pipeline","data-science","data-wrangling","database","mongodb","nosql","pandas","pydantic","pymongo","query-builder","query-engine"],"latest_commit_sha":null,"homepage":"https://vianneymi.github.io/monggregate/","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/VianneyMI.png","metadata":{"files":{"readme":"readme.md","changelog":null,"contributing":"docs/contributing.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2022-09-14T20:50:54.000Z","updated_at":"2025-06-25T21:47:32.000Z","dependencies_parsed_at":"2024-03-27T16:29:45.489Z","dependency_job_id":"a32c8df6-9d5f-4adc-8700-306c2ec90397","html_url":"https://github.com/VianneyMI/monggregate","commit_stats":{"total_commits":126,"total_committers":2,"mean_commits":63.0,"dds":0.05555555555555558,"last_synced_commit":"4f453f36d94471fdb85ecae6b77a03ce109b744f"},"previous_names":[],"tags_count":22,"template":false,"template_full_name":null,"purl":"pkg:github/VianneyMI/monggregate","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/VianneyMI%2Fmonggregate","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/VianneyMI%2Fmonggregate/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/VianneyMI%2Fmonggregate/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/VianneyMI%2Fmonggregate/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/VianneyMI","download_url":"https://codeload.github.com/VianneyMI/monggregate/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/VianneyMI%2Fmonggregate/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":267914097,"owners_count":24164648,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-07-30T02:00:09.044Z","response_time":70,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["aggregation-framework","aggregation-pipeline","data-science","data-wrangling","database","mongodb","nosql","pandas","pydantic","pymongo","query-builder","query-engine"],"created_at":"2025-07-04T17:12:26.678Z","updated_at":"2025-07-30T18:07:09.469Z","avatar_url":"https://github.com/VianneyMI.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# 📊 **Monggregate**\n\n## 📋 **Overview**\n\nMonggregate is a library that aims at simplifying usage of MongoDB aggregation pipelines in Python.\nIt's a lightweight QueryBuilder for MongoDB aggregation pipelines based on [pydantic](https://docs.pydantic.dev/latest/) and compatible with all mongodb drivers and ODMs.\n\n### ✨ **Features**\n\n- 🔄 Provides an Object Oriented Programming (OOP) interface to the aggregation pipeline.\n- 🎯 Allows you to focus on your requirements rather than MongoDB syntax.\n- 📚 Integrates all the MongoDB documentation and allows you to quickly refer to it without having to navigate to the website.\n- 🔍 Enables autocompletion on the various MongoDB features.\n- 🔗 Offers a pandas-style way to chain operations on data.\n- 💻 Mimics the syntax of your favorite tools like pandas\n\n\n## 📥 **Installation**\n\n\u003e 💡 The package is available on PyPI:\n\n```shell\npip install monggregate\n```\n\n\n## 🚀 **Usage**\n\n\u003e 📘 The below examples reference the MongoDB sample_mflix database\n\n### 🔰 **Basic Pipeline usage**\n\n```python\nimport os\n\nfrom dotenv import load_dotenv \nimport pymongo\nfrom monggregate import Pipeline, S\n\n# Creating connexion string securely\n# You need to create a .env file with your password\nload_dotenv(verbose=True)\nMONGODB_URI = os.environ[\"MONGODB_URI\"] \n\n\n# Connect to your MongoDB cluster:\nclient = pymongo.MongoClient(MONGODB_URI)\n\n# Get a reference to the \"sample_mflix\" database:\ndb = client[\"sample_mflix\"]\n\n# Creating the pipeline\npipeline = Pipeline()\n\n# The below pipeline will return the most recent movie with the title \"A Star is Born\"\npipeline.match(\n    title=\"A Star Is Born\"\n).sort(\n    by=\"year\"\n).limit(\n    value=1\n)\n\n# Executing the pipeline\ncurosr = db[\"movies\"].aggregate(pipeline.export())\n\n# Printing the results\nresults = list(curosr)\nprint(results)\n```\n\n\n\n### 🌟 **Advanced Usage, with MongoDB Operators**\n\n\n```python\nimport os\n\nfrom dotenv import load_dotenv \nimport pymongo\nfrom monggregate import Pipeline, S\n\n\n# Creating connexion string securely\nload_dotenv(verbose=True)\nMONGODB_URI = os.environ[\"MONGODB_URI\"]\n\n# Connect to your MongoDB cluster:\nclient = pymongo.MongoClient(MONGODB_URI)\n\n# Get a reference to the \"sample_mflix\" database:\ndb = client[\"sample_mflix\"]\n\n\n# Creating the pipeline\npipeline = Pipeline()\npipeline.match(\n    year=S.type_(\"number\") # Filtering out documents where the year field is not a number\n).group(\n    by=\"year\",\n    query = {\n        \"movie_count\":S.sum(1), # Aggregating the movies per year\n        \"movie_titles\":S.push(\"$title\")\n    }\n).sort(\n    by=\"_id\",\n    descending=True\n).limit(10)\n\n# Executing the pipeline\ncursor = db[\"movies\"].aggregate(pipeline.export())\n\n# Printing the results\nresults = list(cursor)\nprint(results)\n\n```\n\n### 🔥 **Even More Advanced Usage with Expressions**\n\n```python\nimport os\n\nfrom dotenv import load_dotenv \nimport pymongo\nfrom monggregate import Pipeline, S\n\n# Creating connexion string securely\nload_dotenv(verbose=True)\nMONGODB_URI = os.environ[\"MONGODB_URI\"] \n\n# Connect to your MongoDB cluster:\nclient = pymongo.MongoClient(MONGODB_URI)\n\n# Get a reference to the \"sample_mflix\" database:\ndb = client[\"sample_mflix\"]\n\n# Using expressions\ncomments_count = S.size(S.comments)\n\n# Creating the pipeline\npipeline = Pipeline()\npipeline.lookup(\n    right=\"comments\",\n    right_on=\"movie_id\",\n    left_on=\"_id\",\n    name=\"comments\"\n).add_fields(\n    comments_count=comments_count\n).match(\n    expression=comments_count\u003e2\n).limit(1)\n\n# Executing the pipeline\ncursor = db[\"movies\"].aggregate(pipeline.export())\n\n# Printing the results\nresults = list(cursor)\nprint(results)\n```\n\n## 🔍 **Going Further**\n\n* 📚 Check out the [full documentation](https://vianneymi.github.io/monggregate/) for more examples.\n* 📝 Check out this [medium article](https://medium.com/@vianney.mixtur_39698/mongo-db-aggregations-pipelines-made-easy-with-monggregate-680b322167d2).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvianneymi%2Fmonggregate","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fvianneymi%2Fmonggregate","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvianneymi%2Fmonggregate/lists"}