{"id":14976160,"url":"https://github.com/dflor003/graphql-anywhere-mongodb","last_synced_at":"2025-10-27T18:30:45.126Z","repository":{"id":57253335,"uuid":"96586944","full_name":"dflor003/graphql-anywhere-mongodb","owner":"dflor003","description":"Uses graphql-anywhere to build mongodb queries","archived":false,"fork":false,"pushed_at":"2017-11-29T05:12:43.000Z","size":94,"stargazers_count":16,"open_issues_count":0,"forks_count":1,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-02-01T07:31:50.845Z","etag":null,"topics":["graphiql","graphql","graphql-query","mongodb"],"latest_commit_sha":null,"homepage":null,"language":"TypeScript","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/dflor003.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}},"created_at":"2017-07-08T01:05:29.000Z","updated_at":"2024-01-09T02:33:23.000Z","dependencies_parsed_at":"2022-08-31T22:20:15.208Z","dependency_job_id":null,"html_url":"https://github.com/dflor003/graphql-anywhere-mongodb","commit_stats":null,"previous_names":[],"tags_count":10,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dflor003%2Fgraphql-anywhere-mongodb","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dflor003%2Fgraphql-anywhere-mongodb/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dflor003%2Fgraphql-anywhere-mongodb/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dflor003%2Fgraphql-anywhere-mongodb/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/dflor003","download_url":"https://codeload.github.com/dflor003/graphql-anywhere-mongodb/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":238536110,"owners_count":19488659,"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":["graphiql","graphql","graphql-query","mongodb"],"created_at":"2024-09-24T13:53:24.653Z","updated_at":"2025-10-27T18:30:39.762Z","avatar_url":"https://github.com/dflor003.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# graphql-anywhere-mongodb\n\n**WARNING:** This repo is just an experiment, do not use this in production yet.\n\nA library based off [graphql-anywhere](https://github.com/apollographql/graphql-anywhere) that lets you use schemaless GraphQL queries to query documents across one or more MongoDB collections. Use it together with [graphql-tag](https://github.com/apollographql/graphql-tag).\n\nInstall using npm:\n\n```sh\nnpm install --save graphql-tag graphql-anhywhere-mongodb\n```\n\nOr using yarn:\n\n```sh\nyarn add graphql-tag graphql-anywhere-mongodb\n```\n\n## Example App\n\nWanna take this for a spin? See the [graphql-anywhere-mongodb-example](https://github.com/dflor003/graphql-anywhere-mongodb-example) repo for instructions on how to plug this in with [graphql-anywhere-mongodb-express](https://github.com/dflor003/graphql-anywhere-mongodb-express) to be able to make queries into MongoDB using GraphiQL.\n\n## Usage\n\nUse one of the factory functions to create a query executor and then call `find` or `findOne` with a GraphQL query that contains one or more queries around your mongo collections:\n\n```js\nimport graphql from 'graphql-anywhere-mongodb';\nimport gql from 'graphql-tag';\n\nasync function doStuff() {\n  // Can acquire a GraphQLMongoQueryExecutor by passing in a MongoDB URI\n  // this will use the mongo driver to create its own connection\n  const mongo = await graphql.forUri('mongodb://myhost:27017/myDatabase');\n\n  // Alternatively you can use an existing mongo driver connection\n  const myConnection = await fetchConnection();\n  const mongo = graphql.forConnection(myConnection);\n\n  // Then you can start querying mongodb using graphql queries and the\n  // gql string template from the graphql-tag library\n  const query = gql`\n    {\n      users (limit: $limit, skip: $offset) {\n        firstName\n        lastName\n        age (gte: $age)\n        lastLoggedIn (gt: $date)\n        address {\n          city\n          state\n          zip\n        }\n      }\n    }\n  `;\n  const variables = {\n    age: 21,\n    limit: 100,\n    offset: 0,\n    date: new Date('2017-01-17T05:00:00.000Z')\n  };\n  const results = await mongo.find(query, variables);\n}\n```\n\n## Examples\n\n### Querying one or more collections\n\nTop level objects correspond to collections. You can query one or more collections in a single graphql query. For example, assuming we have a collection `users` and `places`, we can make the following query:\n\n```graphql\n# Return firstName and lastName from users\n# AND also return name from places\n{\n  users {\n    firstName\n    lastName\n  }\n  places {\n    name\n  }\n}\n```\n\n### Projection\n\nEvery field name listed will be included in the final projection that you get from MongoDB. This works on nested objects AND arrays. The MongoDB `_id` field is always returned.\n\n```graphql\n{\n  users {\n    firstName\n    lastName\n    address {\n      line1\n      line2\n      city\n      state\n      zip\n    }\n    favoritePlaces {\n      name\n      gps {\n        lat\n        lng\n      }\n    }\n  }\n}\n```\n\nIn cases where you need to filter on a nested object but project the entire outer document you may add `include: true` to the parent document to include it in its entirety. For example, given the same schema as the above query, this would return the entire `address` sub-document, even though we only explicitly call out `zip`:\n\n```graphql\n{\n  users {\n    firstName\n    lastName\n    address (include: true) {\n      zip (eq: \"33326\")\n    }\n  }\n}\n```\n\n### Limit/Skip\n\nYou can add a top-level argument for `limit` and/or `skip` to pass those arguments along to the final mongodb query.\n\n```graphql\n{\n  users (limit: 10, skip 0) {\n    firstName\n    lastName\n  }\n}\n```\n\n### Sorting\n\nIn order to sort by one or more field, annotate the given field with the `@sort` directive for sorting in ascending order or the `@sortDesc` directive for sorting in descending order on that field.\n\n```graphql\n{\n  users (limit: 10, skip 0) {\n    firstName\n    lastName\n    age (gte: 21) @sortDesc\n  }\n}\n```\n\n### Filters\n\nUse standard MongoDB filters like `$eq`, `$ne`, `$gt`, `$gte`, etc. without the `$` prefix as part of your GraphQL query to add filters to your query. See the [MongoDB Docs](https://docs.mongodb.com/manual/reference/operator/query/) for the full list of valid filters.\n\n**Note:** Array filters like `$elemMatch` are not currently supported.\n\n```graphql\n{\n  users (limit: 10, skip: 0) {\n    firstName\n    lastName\n    age (gte: 21)\n    address {\n      city (eq: \"Miami\")\n      state (eq: \"Florida\")\n    }\n  }\n}\n```\n\n## TODO List\n\n- [X] Support basic querying capabilities against MongoDB Collections.\n- [X] Support collection-level things like `limit` and `skip`.\n- [X] Support sorting.\n- [X] Support querying on an inner nexted document while projecting the entire document.\n- [ ] Support more complex data types\n- [X] Support projection of arrays inside documents.\n- [ ] Support filtering of arrays inside documents.\n- [X] GraphiQL-like example to test this against arbitrary MongoDB instances.\n- [ ] Support mutating documents\n- [ ] Support inserting documents\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdflor003%2Fgraphql-anywhere-mongodb","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdflor003%2Fgraphql-anywhere-mongodb","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdflor003%2Fgraphql-anywhere-mongodb/lists"}