A fast and simple MongoDB ODM for Go built on the official Mongo Go Driver.
Mongo Go Models (mgm) is a MongoDB Object-Document Mapper (ODM) for the Go programming language. It provides a higher-level abstraction over the official Mongo Go Driver, simplifying tasks like model definition, CRUD operations, and complex queries. It solves the problem of verbose and repetitive MongoDB code by offering a clean, intuitive API with built-in features like hooks, automatic timestamps, and easy aggregation.
Go developers building applications with MongoDB who want to reduce boilerplate code and simplify database interactions. It's ideal for projects requiring structured model management, lifecycle hooks, and complex querying without sacrificing driver compatibility.
Developers choose mgm because it combines the performance and reliability of the official Mongo Go Driver with a developer-friendly ODM layer. Its unique selling points include built-in hooks for custom logic, predefined MongoDB operators to avoid hardcoding, and seamless integration for transactions and aggregations.
Mongo Go Models (mgm) is a fast and simple MongoDB ODM for Go (based on official Mongo Go Driver)
Supports hooks like Creating, Updating, and Deleting for custom logic such as validation or logging, reducing boilerplate—the README shows how to validate page count in a Creating hook.
Provides builder packages and predefined operators (e.g., operator.Gt) to make complex MongoDB aggregations more readable and less error-prone than hardcoded strings, as demonstrated in the aggregation examples.
DefaultModel automatically adds and manages created_at and updated_at fields, ensuring consistent timestamping across documents with minimal setup, highlighted in the model definition section.
Offers built-in functions like mgm.Transaction() to easily run ACID transactions with MongoDB, leveraging the driver's transaction support without verbose code, as shown in the transactions section.
Defining custom hooks requires manually calling parent DefaultModel hooks (e.g., model.DefaultModel.Creating(ctx)), adding complexity and risk of errors if overlooked, as noted in the hooks documentation.
As a wrapper over the official driver, mgm may lag in supporting the latest MongoDB features or introduce debugging challenges, and its abstraction can obscure direct driver control when needed for advanced use cases.
Requires Go 1.17+ and MongoDB 3.6+, which excludes older projects or environments with legacy dependencies, potentially limiting adoption in enterprise settings with fixed tech stacks.
Redis Go client
Go client for Redis
The Official Golang driver for MongoDB
A fast Golang Redis client that supports Client Side Caching, Auto Pipelining, RDMA, etc.
Open-Awesome is built by the community, for the community. Submit a project, suggest an awesome list, or help improve the catalog on GitHub.