Loading...
Please wait a moment

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

Step 1

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.

•
Paste: Copy your GraphQL query and paste it; the result updates as you type
•
Upload: Select a .graphql or .gql file
•
Sample: See a query with arguments and nested relations converted to MongoDB
Step 2

Automatic Conversion

The converter maps GraphQL concepts to MongoDB CRUD operations:

•
Root fields: Become collection names in db.collection.find()
•
Field selections: Become projection documents ({ name: 1, email: 1 })
•
Arguments: status: "active" becomes a filter, limit: 20 becomes .limit(20)
•
Nested fields: Become separate queries on related collections
Step 3

Copy or Download

•
Copy: Paste directly into the MongoDB Shell or Compass
•
Download: Save as .js

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.