{"id":21558122,"url":"https://github.com/koopjs/koop-provider-mongo","last_synced_at":"2025-07-09T11:07:47.126Z","repository":{"id":25644039,"uuid":"29079423","full_name":"koopjs/koop-provider-mongo","owner":"koopjs","description":"A mongo db provider for koop","archived":false,"fork":false,"pushed_at":"2024-06-24T13:16:57.000Z","size":931,"stargazers_count":2,"open_issues_count":2,"forks_count":4,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-06-22T22:02:03.648Z","etag":null,"topics":["koop-provider"],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/koopjs.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","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}},"created_at":"2015-01-11T03:00:14.000Z","updated_at":"2023-10-17T14:23:38.000Z","dependencies_parsed_at":"2023-01-14T03:02:58.356Z","dependency_job_id":"519bf44b-5c2f-4743-a594-7d16c863da91","html_url":"https://github.com/koopjs/koop-provider-mongo","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/koopjs/koop-provider-mongo","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/koopjs%2Fkoop-provider-mongo","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/koopjs%2Fkoop-provider-mongo/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/koopjs%2Fkoop-provider-mongo/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/koopjs%2Fkoop-provider-mongo/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/koopjs","download_url":"https://codeload.github.com/koopjs/koop-provider-mongo/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/koopjs%2Fkoop-provider-mongo/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":264446722,"owners_count":23609633,"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","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":["koop-provider"],"created_at":"2024-11-24T08:14:02.883Z","updated_at":"2025-07-09T11:07:47.105Z","avatar_url":"https://github.com/koopjs.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# koop-provider-mongo\n\nProvider to fetch data from a MongoDb instance.  It can access any database/collection on your instance by assigning the `id` route-parameter a delimited value in the form of `database-name::collection-name`.\n\n## Data considerations\nAs per MongoDB specifications, [each document/record in your dataset will have a unique-identifier](https://www.mongodb.com/docs/manual/core/document/#the-_id-field), `_id`.  At insert time, you can choose to assign this value manually, or allow Mongo to generate it automatically. In terms of your provider metadata, this means that you could always use `_id` as the value of your provider's `idField` (an attribute used to flag which GeoJSON property is the unique-identifier).\n\nIf your data has a geometry, you should consider using [geospatial index](https://www.mongodb.com/docs/manual/core/indexes/index-types/index-geospatial/).  While not necessary, it will likely speed any queries including a geometry operation.\n\n## Usage\n\nRegister the provider with Koop:\n\n```js\nconst Koop = require('@koopjs/koop-core');\nconst koop = new Koop({ logLevel: 'info'});\nconst mongoProvider = require('@koopjs/provider-mongodb');\n\nkoop.register(mongoProvider, { connnectString, databases });\n```\n\n### Registration/Config parameters\nThe provider can be configured with registration options or the use of the `config` module with an entry key `\"mongodb\"` in the JSON configuration document.  See below, for an example of using the `config` approach \n\n\n#### `connectString`: string\nA MongoDB connection string, e.g., `mongodb://localhost:27017`. \n\n#### `databases`: object\nA key/value populated object that serves as a metadata lookup/dictionary for any database/collection on your MongoDB instance that you wish to provide access.  For example, if imagine you have a database called `db1` and it has a collection called `my-collection`.  You can set up the `databases` object so as to provide metadata for `my-collection`:\n\n```js\n{\n  db1: {\n    'my-collection': {\n      geometryField: 'location', // field holding a record's GeoJSON geometry.\n      idField: '_id', // field to treat as the unique-id.  Default: `_id`.\n      cacheTtl: 0, // number of seconds to cache results from MongoDb. Default: 0.\n      crs: 4326, // Coordinate reference system of geometry. Default: 4326.\n      maxRecordCount: 2000, // Max number of records to return in a page. Default: 2000.\n    }\n  }\n}\n```\n\nNote that for each collection, you may configure the options above.  If you do not assign a field to `geometryField`, the collection will be treated like tabular data, and the GeoJSON generated will have no geometry,\n\n#### `definedCollectionsOnly`: boolean\nThis setting determines if the database/collection must appear in the `databases` parameter to be accessed. Defaults to `true`.\n\n\n#### Setting with the \"config\" module\nKoop allows providers to use the [`config` module](https://github.com/node-config/node-config). The settings above can be stored in a config JSON under the key `mongodb`:\n\n```json\n{\n  \"mongodb\": {\n      \"connectString\": \"mongodb://localhost:27017\",\n      \"databases\": {\n        \"cdf-sample-data\": {\n          \"fires\": {\n            \"geometryField\": \"location\",\n            \"idField\": \"_id\",\n            \"cacheTtl\": 0,\n            \"crs\": 4326,\n            \"maxRecordCount\": 2000\n          }\n        }\n      }\n  }\n}\n```\n\n## Route parameters\n\n#### `id`\nOnce registered with Koop, the provide will expose routes with an `id` parameter. For example:\n\n```sh\n/mongodb/rest/services/:id/FeatureServer\n```\n\nThe `id` parameter should be filled with a `::` delimited string with the target `\u003cdatabase\u003e::\u003ccollection\u003e`.  For example, a request like:\n\n```sh\n/mongodb/rest/services/sample-db::fires/FeatureServer/0/query\n```\n\nwould return records from the `fires` _collection_ in the `sample-db` _database_. \n\n## Demo\n\nThe repository includes a demonstration project.  To run the demo you will need Docker installed on your computer. Once installed you can following the steps below to create a local Elastic instance and load it with sample data:\n\n```sh\n\u003e npm install\n\n\u003e cd demo\n\n# use Docker to run Elastic/Kibana\n\u003e docker-compose up -d\n\n# load sample data; this will create an MongoDB database called \"sample-data' with a collection named \"fires\"\n\u003e node loader.js \n\n# start the Koop application\n\u003e node index.js\n```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkoopjs%2Fkoop-provider-mongo","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkoopjs%2Fkoop-provider-mongo","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkoopjs%2Fkoop-provider-mongo/lists"}