{"id":23002650,"url":"https://github.com/treedomtrees/opal-fetcher-mongodb","last_synced_at":"2025-08-14T01:31:26.952Z","repository":{"id":233008524,"uuid":"680188196","full_name":"treedomtrees/opal-fetcher-mongodb","owner":"treedomtrees","description":"An OPAL fetch provider to bring authorization state from MongoDB.","archived":false,"fork":false,"pushed_at":"2024-09-11T08:52:48.000Z","size":26,"stargazers_count":4,"open_issues_count":0,"forks_count":0,"subscribers_count":5,"default_branch":"master","last_synced_at":"2025-07-27T23:42:51.406Z","etag":null,"topics":["mongodb","opal","opal-fetcher"],"latest_commit_sha":null,"homepage":"https://pypi.org/project/opal-fetcher-mongodb/","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/treedomtrees.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"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},"funding":{"custom":["https://www.treedom.net/en/organization/treedom/event/treedom-open-source?utm_source=github"]}},"created_at":"2023-08-18T14:55:11.000Z","updated_at":"2025-01-18T12:09:10.000Z","dependencies_parsed_at":"2024-04-12T23:06:00.563Z","dependency_job_id":"bdcfa79f-8b12-4bf3-bc43-2a93ff1eff90","html_url":"https://github.com/treedomtrees/opal-fetcher-mongodb","commit_stats":null,"previous_names":["treedomtrees/opal-fetcher-mongodb"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/treedomtrees/opal-fetcher-mongodb","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/treedomtrees%2Fopal-fetcher-mongodb","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/treedomtrees%2Fopal-fetcher-mongodb/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/treedomtrees%2Fopal-fetcher-mongodb/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/treedomtrees%2Fopal-fetcher-mongodb/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/treedomtrees","download_url":"https://codeload.github.com/treedomtrees/opal-fetcher-mongodb/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/treedomtrees%2Fopal-fetcher-mongodb/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":270347431,"owners_count":24568569,"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-08-13T02:00:09.904Z","response_time":66,"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":["mongodb","opal","opal-fetcher"],"created_at":"2024-12-15T07:11:55.685Z","updated_at":"2025-08-14T01:31:26.667Z","avatar_url":"https://github.com/treedomtrees.png","language":"Python","funding_links":["https://www.treedom.net/en/organization/treedom/event/treedom-open-source?utm_source=github"],"categories":[],"sub_categories":[],"readme":"\u003cp  align=\"center\"\u003e\n \u003cimg src=\"https://github.com/permitio/opal/assets/4082578/4e21f85f-30ab-43e2-92de-b82f78888c71\" height=170 alt=\"opal\" border=\"0\" /\u003e\n\u003c/p\u003e\n\u003ch2 align=\"center\"\u003e\nOPAL Fetcher for MongoDB\n\u003c/h2\u003e\n\n\u003ch4 align=\"center\"\u003e\nMade with ❤️ at \u003ca href=\"https://treedom.net\"\u003e\u003cimg src=\"https://i.ibb.co/QfYVtP5/Treedom-logo.png\" height=\"24\" alt=\"treedom\" border=\"0\" /\u003e\u003c/a\u003e, \u003ca href=\"#-join-us-in-making-a-difference-\"\u003ejoin us in making a difference\u003c/a\u003e!\n\u003c/h4\u003e\n\n\u003ch6 align=\"center\"\u003e\n\u003ca href=\"https://www.treedom.net/it/organization/treedom/event/treedom-open-source\"\u003e\u003cimg src=\"https://badges.treedom.net/badge/f/treedom-open-source?2\" alt=\"plant-a-tree\" border=\"0\" /\u003e\u003c/a\u003e\n\u003c/h6\u003e\n\n[Check out OPAL main repo here.](https://github.com/permitio/opal)\n\n\n### What's in this repo?\nAn OPAL [custom fetch provider](https://docs.opal.ac/tutorials/write_your_own_fetch_provider) to bring authorization state from [MongoDB](https://www.mongodb.com/).\n\n### How to try this custom fetcher in one command? (Example docker-compose configuration)\n\nYou can test this fetcher with the example docker compose file in this repository root. Clone this repo, `cd` into the cloned repo, and then run:\n```\ndocker compose up\n```\nthis docker compose configuration already correctly configures OPAL to load the MongoDB Fetch Provider, and correctly configures `OPAL_DATA_CONFIG_SOURCES` to include an entry that uses this fetcher.\n\n### ✏️ How to use this fetcher in your OPAL Setup\n\n#### 1) Build a custom opal-client `Dockerfile`\n\nThe official docker image only contains the built-in fetch providers. You need to create your own `Dockerfile` (that is based on the official docker image), that includes this fetcher's pip package.\n\nYour `Dockerfile` should look like this:\n```\nFROM permitio/opal-client:latest\nRUN pip install --no-cache-dir --user opal-fetcher-mongodb\n```\n\n#### 2) Build your custom opal-client container\nSay your special Dockerfile from step one is called `custom_client.Dockerfile`.\n\nYou must build a customized OPAL container from this Dockerfile, like so:\n```\ndocker build -t yourcompany/opal-client -f custom_client.Dockerfile .\n```\n\n#### 3) When running OPAL, set `OPAL_FETCH_PROVIDER_MODULES`\nPass the following environment variable to the OPAL client docker container (comma-separated provider modules):\n```\nOPAL_FETCH_PROVIDER_MODULES=opal_common.fetcher.providers,opal_fetcher_mongodb.provider\n```\nNotice that OPAL receives a list from where to search for fetch providers.\nThe list in our case includes the built-in providers (`opal_common.fetcher.providers`) and our custom MongoDB provider.\n\n#### 4) Using the custom provider in your DataSourceEntry objects\n\nYour DataSourceEntry objects (either in `OPAL_DATA_CONFIG_SOURCES` or in dynamic updates sent via the OPAL publish API) can now include this fetcher's config.\n\nExample value of `OPAL_DATA_CONFIG_SOURCES` (formatted nicely, but in env var you should pack this to one-line and no-spaces):\n```json\n{\n  \"config\": {\n    \"entries\": [\n      {\n        \"url\": \"mongodb://user:password@mongodb/test_database?authSource=admin\",\n        \"config\": {\n          \"fetcher\": \"MongoDBFetchProvider\",\n          \"database\": \"opal_fetcher_mongodb\",\n          \"collection\": \"cities_collection\",\n          \"find\": { \"query\": {} }\n        },\n        \"topics\": [\"policy_data\"],\n        \"dst_path\": \"cities\"\n      }\n    ]\n  }\n}\n```\n\nNotice how `config` is an instance of `MongoDBFetchProvider` (code is in `opal_fetcher_mongodb/provider.py`).\n\nValues for this fetcher config:\n* The `url` is actually a MongoDB uri.\n* Your `config` must include the `fetcher` key to indicate to OPAL that you use a custom fetcher.\n* Your `config` must include the `collection` key to indicate what collection to query in MongoDB.\n* Your `config` may include the `database` key to indicate what database to query in MongoDB. If not specified, the default database will be used.\n* Your `config` must include one of `findOne`, `find` or `aggregate` keys to indicate what query to run against MongoDB.\n* Your `config` may include the `transform` key to transform the results from the `find` or `aggregate` queries.\n\n#### Query methods\nAll the three available query methods accept the same input parameters as defined in the MongoDB documentation.\n\n##### findOne\n\n* `findOne` - [MongoDB docs](https://docs.mongodb.com/manual/reference/method/db.collection.findOne/)\n\n\u003cdetails\u003e\n  \u003csummary\u003eExample configuration\u003c/summary\u003e\n\n```json\n{\n  \"config\": {\n    \"entries\": [\n      {\n        ...\n        \"config\": {\n          ...\n          \"findOne\": {\n            \"query\": {\n              ...\n            },\n            \"projection\": {\n              ...\n            },\n            \"options\": {\n              ...\n            }\n          }\n        }\n      }\n    ]\n  }\n}\n```\n\u003c/details\u003e\n\n##### find\n\n* `find` - [MongoDB docs](https://docs.mongodb.com/manual/reference/method/db.collection.find/)\n\n\u003cdetails\u003e\n  \u003csummary\u003eExample configuration\u003c/summary\u003e\n\n```json\n{\n  \"config\": {\n    \"entries\": [\n      {\n        ...\n        \"config\": {\n          ...\n          \"find\": {\n            \"query\": {\n              ...\n            },\n            \"projection\": {\n              ...\n            },\n            \"options\": {\n              ...\n            }\n          },\n          \"transform\": {\n            \"first\": false,\n            \"mapKey\": \"\",\n            \"merge\": true\n          }\n        }\n      }\n    ]\n  }\n}\n```\n\u003c/details\u003e\n\n##### aggregate\n\n* `aggregate` - [MongoDB docs](https://docs.mongodb.com/manual/reference/method/db.collection.aggregate/)\n\n\u003cdetails\u003e\n  \u003csummary\u003eExample configuration\u003c/summary\u003e\n\n```json\n{\n  \"config\": {\n    \"entries\": [\n      {\n        ...\n        \"config\": {\n          ...\n          \"aggregate\": {\n            \"pipeline\": [\n              ...\n            ],\n            \"options\": {\n              ...\n            }\n          },\n          \"transform\": {\n            \"first\": false,\n            \"mapKey\": \"\"\n          }\n        }\n      }\n    ]\n  }\n}\n```\n\u003c/details\u003e\n\n#### Query transform\n`transform` allows you to transform the results from the `find` or `aggregate` queries.\n\n##### first\n`transform.first` allows you to return only the first result from the query.\n\nEquivalent to the following Python code:\n\n```python\nresult = query_result[0]\n```\n\n##### mapKey\n`transform.mapKey` allows you to map the original list-like result to a dictionary-like result using the property specified in the `mapKey` as the key for the dictionary.\n\nEquivalent to the following Python code:\n\n```python\nresult = {}\nfor item in query_result:\n    result[item['key']] = item\n```\n\n\u003e Only properties in the root of the document can be used as the key for the dictionary.\n\n##### merge\n\n`transform.merge` allows you to merge the results from the query into a single document. Duplicate keys will be overwritten by the last document in the list.\n\nEquivalent to the following Python code:\n\n```python\nresult = {}\nfor item in query_result:\n    for key, value in item.items():\n        result[key] = value\n```\n\n## 🌳 Join Us in Making a Difference! 🌳\n\nWe invite all developers who use Treedom's open-source code to support our mission of sustainability by planting a tree with us. By contributing to reforestation efforts, you help create a healthier planet and give back to the environment. Visit our [Treedom Open Source Forest](https://www.treedom.net/en/organization/treedom/event/treedom-open-source) to plant your tree today and join our community of eco-conscious developers.\n\nAdditionally, you can integrate the Treedom GitHub badge into your repository to showcase the number of trees in your Treedom forest and encourage others to plant new ones. Check out our [integration guide](https://github.com/treedomtrees/.github/blob/main/profile/README.md) to get started.\n\nTogether, we can make a lasting impact! 🌍💚\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftreedomtrees%2Fopal-fetcher-mongodb","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftreedomtrees%2Fopal-fetcher-mongodb","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftreedomtrees%2Fopal-fetcher-mongodb/lists"}