This Hasura data connector connects MongoDB to your data graph giving you an instant GraphQL API to access your MongoDB data. Supports MongoDB 6 or later.
This connector is built using the Rust Data Connector SDK and implements the Data Connector Spec.
Docs for the MongoDB data connector:
Below, you'll find a matrix of all supported features for the MongoDB data connector:
Feature | Supported | Notes |
---|---|---|
Native Queries + Logical Models | ✅ | |
Simple Object Query | ✅ | |
Filter / Search | ✅ | |
Filter by fields of Nested Objects | ✅ | |
Filter by values in Nested Arrays | ✅ | |
Simple Aggregation | ✅ | |
Aggregate fields of Nested Objects | ❌ | |
Aggregate values of Nested Arrays | ❌ | |
Sort | ✅ | |
Sorty by fields of Nested Objects | ❌ | |
Paginate | ✅ | |
Collection Relationships | ✅ | |
Remote Relationships | ✅ | |
Relationships Keyed by Fields of Nested Objects | ❌ | |
Mutations | ✅ | Provided by custom Native Mutations - predefined basic mutations are also planned |
- The DDN CLI and Docker installed
- A supergraph
- A subgraph
The steps below explain how to initialize and configure a connector for local development on your data graph. You can learn how to deploy a connector — after it's been configured — here.
For instructions on local development on the MongoDB connector itself see development.md.
ddn auth login
Once you have an initialized supergraph and subgraph, run the initialization command in interactive mode while providing a name for the connector in the prompt:
ddn connector init <connector-name> -i
<connector-name>
may be any name you choose for your particular project.
The CLI will ask for a specific port to run the connector on. Choose a port that is not already in use or use the default suggested port.
Name | Description |
---|---|
MONGODB_DATABASE_URI |
Connection URI for the MongoDB database to connect - see notes below |
MONGODB_DATABASE_URI
is a string with your database' hostname, login
credentials, and database name. A simple example is
mongodb://admin@pass:localhost/my_database
. If you are using a hosted database
on MongoDB Atlas you can get the URI from the "Data Services" tab in the project
dashboard:
- open the "Data Services" tab
- click "Get connection string"
- you will see a 3-step dialog - ignore all 3 steps, you don't need to change anything
- copy the string that begins with
mongodb+srv://
Set up configuration for the connector with this command. This will introspect your database to infer a schema with types for your data.
ddn connector introspect <connector-name>
Remember to use the same value for <connector-name>
That you used in step 2.
This will create a tree of files that looks like this (this example is based on the sample_mflix sample database):
app/connector
└── <connector-name>
├── compose.yaml -- defines a docker service for the connector
├── connector.yaml -- defines connector version to fetch from hub, subgraph, env var mapping
├── configuration.json -- options for configuring the connector
├── schema -- inferred types for collection documents - one file per collection
│ ├── comments.json
│ ├── movies.json
│ ├── sessions.json
│ ├── theaters.json
│ └── users.json
├── native_mutations -- custom mongodb commands to appear in your data graph
│ └── your_mutation.json
└── native_queries -- custom mongodb aggregation pipelines to appear in your data graph
└── your_query.json
The native_mutations
and native_queries
directories will not be created
automatically - create those directories as needed.
Feel free to edit these files to change options, or to make manual tweaks to
inferred schema types. If inferred types do not look accurate you can edit
configuration.json
, change sampleSize
to a larger number to randomly sample
more collection documents, and run the introspect
command again.
This command will query the MongoDB connector to produce DDN metadata that declares resources provided by the connector in your data graph.
ddn connector-link add-resources <connector-name>
The connector must be running before you run this command! If you have not
already done so you can run the connector with ddn run docker-start
.
If you have changed the configuration described in Step 3 it is important to
restart the connector. Running ddn run docker-start
again will restart the
connector if configuration has changed.
This will create and update DDN metadata files. Once again this example is based on the sample_mflix data set:
app/metadata
├── mongodb.hml -- DataConnectorLink has connector connection details & database schema
├── mongodb-types.hml -- maps connector scalar types to GraphQL scalar types
├── Comments.hml -- The remaining files map database collections to GraphQL object types
├── Movies.hml
├── Sessions.hml
├── Theaters.hml
└── Users.hml
View the full documentation for the MongoDB connector here.
Check out our contributing guide for more details.
The MongoDB connector is available under the Apache License 2.0.