Build and evolve your APIs on MongoDB data
What makes for a great API on MongoDB
- Clear documentation
- Type safety
- Version control
- Features like pagination, filtering, and sorting
- The ability to query nested data
- Joining data from different collections
- Solid security and authorization
- Fast performance
- Support for MongoDB's special features like Vector Search and Time Series
How Hasura DDN makes life easier
- Autogenerated schemas: When you connect MongoDB to Hasura, GraphQL schemas will be autogenerated for you based on a MongoDB JSON validation schema, if one is available, or by sampling documents to determine what the schema should be. You can then customize these as needed to tailor the GraphQL layer to fit your application requirements closely.
- Mutations: Native mutations allow you to run custom commands on your MongoDB database using the runCommand API that can be exposed via the Hasura GraphQL and modify the database state.
- Easy-to-use documentation: You instantly get a self-documented GraphQL API and a searchable data graph of not only MongoDB but all data sources and business logic that are part of the API. Using Hasura Console’s explorer UI, you can see a top-down view of your supergraph. Hasura DDN allows you to organize your data sources and business logic as domains so consumers better understand your data structure.
- Nested data queries: Easily work with MongoDB's nested documents and arrays. Hasura’s autogenerated API allows users to query data found in nested arrays or objects. Furthermore, users can specify what fields they want returned and the structure of the response.
- Advanced querying: Features like pagination, filtering, nested object filtering, and sorting are built-in. Pagination controls the volume of data sent in a single response, reducing the load on the server and client, preventing performance bottlenecks, and enhancing user experience by allowing data to be consumed in manageable chunks. Pagination, filtering, and sorting all improve the functionality and usability of an API.
- Join collections: Although MongoDB is a NoSQL database, it offers the $lookup aggregation stage that acts like an SQL join. Using MongoDB and Hasura together gives you the best of NoSQL and relational databases, so you can join data from MongoDB to other data sources as needed.
- Remote joins: Remote joins enable developers to seamlessly integrate data from diverse sources, treating them as a unified database without modifying existing data structures. This feature addresses the challenge of data fragmentation across multiple APIs, databases, and microservices by providing a data access layer that can join data across databases and remote data sources. It allows for creating relationships between database types and API-derived types, facilitating "joins" while maintaining security and authorization.
- High performance: The MongoDB connector builds efficient query plans using MongoDB aggregation pipelines. The connector can execute each GraphQL query using a single request to MongoDB, including queries with relations between collections in the same database, and queries referencing native queries.
- Type safety: By introducing a structured type system on top of the schemaless nature of NoSQL databases, GraphQL facilitates a more organized approach to data handling. This structure ensures that while the flexibility and utility of typeless systems are maintained, applications still enforce a consistent, well-defined schema that evolves with the development process.
- Observability: Leverage an out-of-the-box, powerful set of tools that help you monitor and debug your API. With observability, you can check performance, debug errors, and get insights into your API usage.
- Versioning and API evolution: Direct modifications to the API can result in breaking changes that disrupt client applications. Hasura addresses this challenge by utilizing the @deprecated schema directive in GraphQL. This feature allows you to mark fields as deprecated and provide a reason, effectively notifying your API consumers about the changes without causing immediate disruptions.
Versioning helps maintain stability and backward compatibility as your API evolves. Learn more about API versioning through field deprecation here. - Robust security: Robust security is achieved through fine-grained permissions that control data access. This allows you to determine precisely what data each verified user can access. By implementing detailed authorization rules, organizations can maintain strict control over their data, ensuring that users only see and interact with the information they're supposed to.
- Custom business logic: Hasura DDN allows for writing custom business logic using the Node.js Lambda Connector with TypeScript. Users can expose generic functions or procedures that can be added to metadata as a command. This custom business logic can leverage the same relationship and permissions features available for collection making them an interconnected part of your API or supergraph.
Coming soon and upcoming features
- Aggregations: Aggregations allow you to summarize and calculate the collective properties of data. They process large datasets efficiently, condensing information into key metrics and revealing data trends and patterns.
- Autogenerated mutations: Currently you can generate mutations using Hasura MongoDB native mutations, but with this addition, Hasura will generate simple point mutations for you automatically.
- Advance querying: Filter your collections based on nested arrays. Order your collections based on nested documents or nested arrays.
- Native query DX improvements: Pass a js file containing your MongoDB aggregation pipeline to the Hasura MongoDB connector cli plugin to have native operations generated for you. For more on native operations visit our docs.
- Nested collection joins: Combine data from different collections or remote sources to and from your nested data.
- Subscriptions: Live queries and streaming subscriptions for MongoDB.
Getting started
Related reading