Skip to content

What is MODM?

Go Report CardGoGo ReferenceGitHubCoverage Status

This document was translated using GPT-4o.

MODM is an ODM (Object-Document Mapper) library for MongoDB, designed for use with Go version 1.18 and above. It leverages generics instead of code generation and other similar approaches.

TIP

MODM is designed with the principles of simplicity, convenience, and practicality in mind. Therefore, it aims to maintain consistency with the official MongoDB driver in terms of types and syntax as much as possible.

Features

  • Direct return of structured data in CRUD operations
  • No need for code generation
  • Flexible hooks
  • Automated field management
  • Synchronized indexes
  • User-friendly transactions

Use Cases

go
db := DB{
    Users: modm.NewRepo[*User](database.Collection("users")),
}
// Find() returns ([]*User, error)
users, _ := db.Users.Find(ctx, bson.M{"age": 18})

TIP

You can check out the complete example in the Getting Started section.

Released under the MIT License.