Build and evolve your APIs on MongoDB data

If you haven’t already heard, we recently launched the GA of our flagship product, Hasura Data Delivery Network (DDN)! We’re also excited to release Hasura’s native data connector for MongoDB. With this GraphQL-powered connector, users can autogenerate performant, composable APIs for data stored in MongoDB on Hasura DDN.

Creating a robust API for MongoDB is about more than just connecting to the database. In the sections below, we’ll outline what goes into a good GraphQL API for MongoDB, what it takes to build and maintain one, and how Hasura’s new framework allows developers to kickstart new projects and scale existing projects rapidly.

What makes for a great API on MongoDB

Creating a great API on MongoDB involves several key components that enhance functionality, usability, and performance. These essential elements are as follows:

  • 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

Normally, building all this would take a ton of time and effort. But here's where Hasura DDN comes in to save the day.

How Hasura DDN makes life easier

Hasura DDN abstracts away the complexity of MongoDB’s schema-less model, giving you a more structured approach to work with through its intuitive and declarative domain-first modeling framework. You can quickly set up your data models, permissions, and relationships using Hasura's intuitive tools. The best part? It automatically generates standardized API endpoints for you.

This means you don't have to manually write complex aggregation pipelines to deal with nested documents or arrays. Hasura DDN offers advanced features like cross-domain joins, nested filtering, and sorting right out of the box.

These features, which are typically challenging and time-consuming to code, are now effortless, allowing developers to fetch, filter, and aggregate any shape of data on demand. As a result, development teams can build faster and businesses can launch products more efficiently.

Critical features of Hasura’s MongoDB connector:

  1. 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.
  2. 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.
  3. 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.
  4. 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.
  5. 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.
  6. 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.
  7. 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.
  8. 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.
  9. 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.
  10. 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.
  11. 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.
  12. 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.
  13. 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

  1. 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.
  2. 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.
  3. Advance querying: Filter your collections based on nested arrays. Order your collections based on nested documents or nested arrays.
  4. 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.
  5. Nested collection joins: Combine data from different collections or remote sources to and from your nested data.
  6. Subscriptions: Live queries and streaming subscriptions for MongoDB.

Getting started

Ready to give it a try? Check out our docs, and start for free here.

Want to learn more? You can follow our getting started guide or book a demo to see Hasura DDN in action.

Blog
12 Aug, 2024
Email
Subscribe to stay up-to-date on all things Hasura. One newsletter, once a month.
Loading...
v3-pattern
Accelerate development and data access with radically reduced complexity.