GraphQL to MongoDB Converter Online — Convert GraphQL Queries to MongoDB
Paste your GraphQL query above and get the equivalent MongoDB find() calls. Field selections become projections, arguments become filter conditions, and nested fields get their own find() on a related collection. It all runs in your browser and the result is MongoDB shell-compatible output.
How to Convert GraphQL to MongoDB — Step-by-Step
Input Your GraphQL Query
Need to understand what MongoDB query a GraphQL query maps to? Paste it from your GraphiQL playground, Apollo Explorer, or application code.
.graphql or .gql fileAutomatic Conversion
The converter maps GraphQL concepts to MongoDB CRUD operations:
db.collection.find(){ name: 1, email: 1 })status: "active" becomes a filter, limit: 20 becomes .limit(20)Copy or Download
Frequently Asked Questions
How does a GraphQL query map to MongoDB?
Each top-level field is read as a collection name, so users(status: "active") { name email } becomes db.users.find({ status: "active" }, { name: 1, email: 1 }). Arguments turn into filter conditions and the fields you select become the projection. The converter only looks at the query text; it has no idea how your real resolvers fetch data, so treat the output as a starting point.
Which arguments become sort, skip and limit?
limit and first become .limit(), offset and skip become .skip(), and orderBy or sortBy become .sort(). orderBy can be a string such as "price DESC", an object such as { price: DESC, name: ASC }, or a list of those. Every other argument goes into the filter.
What happens to nested fields?
A nested field that has its own selection, like reviews(rating: 5) { text }, gets its own find() on a collection with that name, written under a "Related" comment. Nothing is joined: you still have to link the two results yourself, for example with the parent id.
Are long IDs and decimals kept exactly?
Yes. Whole numbers that JavaScript can hold are written as typed. Bigger ones, such as an ICCID like 8901240544102066246, are written as NumberLong("8901240544102066246") so mongosh keeps every digit, and anything past 64 bits becomes NumberDecimal("..."). Decimals like 14.50 and quoted values like "00501" are copied exactly as you wrote them.
Can it convert mutations, variables or fragments?
Fragments and inline fragments are expanded into the fields they contain. Mutations and subscriptions are refused with a message, since they have no find() equivalent. A variable such as $id has no value inside the query text, so you are asked to replace it with the real value first.
Does my query leave the browser?
No. The query is parsed with the graphql-js library inside your browser and nothing is uploaded. It costs nothing and needs no account.
Also try: MongoDB to GraphQL, GraphQL to SQL, GraphQL to REST, GraphQL Formatter.
Related Tools
GraphQL Query Formatter
Format and beautify GraphQL queries and schemas with syntax highlighting
GraphQL Schema Validator
Validate GraphQL schemas with syntax and structure checking
GraphQL Fixer
Fix broken GraphQL queries and schemas automatically, repair syntax errors and malformed types
GraphQL to TypeScript
Generate TypeScript types from GraphQL schemas and queries
GraphQL Minifier
Compress and optimize GraphQL queries for production
GraphQL to JSON Schema
Convert GraphQL schemas to JSON Schema format