Open-Awesome
CategoriesAlternativesStacksSelf-HostedExplore
Open-Awesome

© 2026 Open-Awesome. Curated for the developer elite.

TermsPrivacyAboutGitHubRSS
  1. Home
  2. Go
  3. mgm

mgm

Apache-2.0Go

A fast and simple MongoDB ODM for Go built on the official Mongo Go Driver.

GitHubGitHub
765 stars63 forks0 contributors

What is mgm?

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.

Target Audience

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.

Value Proposition

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.

Overview

Mongo Go Models (mgm) is a fast and simple MongoDB ODM for Go (based on official Mongo Go Driver)

Use Cases

Best For

  • Building Go web applications with MongoDB as the backend database
  • Reducing boilerplate code for MongoDB CRUD operations in Go
  • Implementing model lifecycle hooks (e.g., validation, logging) in Go
  • Simplifying complex MongoDB aggregations and queries in Go
  • Managing database transactions with MongoDB in Go applications
  • Structuring MongoDB models with automatic timestamps and IDs

Not Ideal For

  • Projects requiring raw, unabstracted access to the Mongo Go Driver for fine-grained query optimization or custom driver features
  • Teams building applications with multiple database backends that need a database-agnostic data layer or ORM
  • Performance-critical systems where the overhead of an ODM's reflection and additional method calls could impact latency or throughput

Pros & Cons

Pros

Lifecycle Hooks

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.

Aggregation Simplification

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.

Automatic Timestamps

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.

Transaction Integration

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.

Cons

Hook Invocation Burden

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.

Abstraction Limitations

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.

Version Constraints

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.

Frequently Asked Questions

Quick Stats

Stars765
Forks63
Contributors0
Open Issues13
Last commit2 months ago
CreatedSince 2019

Tags

#model#transaction-support#mongo#golang-library#mongodb#crud-operations#go#odm

Built With

G
Go

Included in

Go169.1k
Auto-fetched 1 day ago

Related Projects

redisredis

Redis Go client

Stars22,068
Forks2,548
Last commit1 day ago
redigoredigo

Go client for Redis

Stars9,872
Forks1,243
Last commit6 months ago
mongo-go-drivermongo-go-driver

The Official Golang driver for MongoDB

Stars8,523
Forks925
Last commit3 days ago
rueidisrueidis

A fast Golang Redis client that supports Client Side Caching, Auto Pipelining, RDMA, etc.

Stars2,940
Forks240
Last commit2 days ago
Community-curated · Updated weekly · 100% open source

Found a gem we're missing?

Open-Awesome is built by the community, for the community. Submit a project, suggest an awesome list, or help improve the catalog on GitHub.

Submit a projectStar on GitHub