MongORM is a production-ready, type-safe MongoDB ORM for Go that combines generics, fluent query building, and predictable data modeling. It helps Go teams ship faster with clean CRUD workflows, typed filters, aggregation support, and transaction-safe operations.
If you are building backend APIs, SaaS products, internal tools, or data-heavy services on MongoDB, MongORM gives you a high-signal developer experience without hiding core MongoDB power.
Open source by Azayn Labs
| Home: azayn.com | LinkedIn: linkedin.com/company/azayn-labs |
GitHub Profile: github.com/azayn-labs
GitHub Project: MongORM
Where(), Sort(), Limit(), Skip(), Projection(), keyset pagination helpers, Set(), and Unset()FindOneAs[T, R]() and FindAllAs[T, R]()BulkWrite(), BulkWriteInTransaction(), and NewBulkWriteBuilder[T]()Aggregate(), AggregateRaw(), AggregateAs[T, R](), and AggregatePipeline()Count(), Distinct(), DistinctFieldAs[T, V](), DistinctStrings(), DistinctInt64(), DistinctBool(), DistinctFloat64(), DistinctObjectIDs(), and DistinctTimes()GeoField with Near, Within, and Intersects query helpersEnsure2DSphereIndex(), and EnsureGeoDefaults()WithTransaction() for atomic multi-operation workflowsmongorm:"version" (_version) and ErrOptimisticLockConflictErrNotFound, ErrDuplicateKey, ErrInvalidConfig, ErrTransactionUnsupportedCreatedAt / UpdatedAt timestamp managementgo get github.com/azayn-labs/mongorm
package main
import (
"context"
"fmt"
"github.com/azayn-labs/mongorm"
"github.com/azayn-labs/mongorm/primitives"
"go.mongodb.org/mongo-driver/v2/bson"
)
type ToDo struct {
ID *bson.ObjectID `bson:"_id,omitempty" mongorm:"primary"`
Text *string `bson:"text,omitempty"`
// Connection embedded in struct tags
connectionString *string `mongorm:"mongodb://localhost:27017,connection:url"`
database *string `mongorm:"mydb,connection:database"`
collection *string `mongorm:"todos,connection:collection"`
}
type ToDoSchema struct {
ID *primitives.ObjectIDField
Text *primitives.StringField
}
var ToDoFields = mongorm.FieldsOf[ToDo, ToDoSchema]()
func main() {
ctx := context.Background()
// Create
todo := &ToDo{Text: mongorm.String("Buy groceries")}
orm := mongorm.New(todo)
if err := orm.Save(ctx); err != nil {
panic(err)
}
fmt.Printf("Created: %s\n", todo.ID.Hex())
// Find by ID
found := &ToDo{}
mongorm.New(found).Where(ToDoFields.ID.Eq(*todo.ID)).First(ctx)
fmt.Printf("Found: %s\n", *found.Text)
// Update
mongorm.New(&ToDo{}).
Where(ToDoFields.ID.Eq(*todo.ID)).
Set(&ToDo{Text: mongorm.String("Buy organic groceries")}).
Save(ctx)
// Delete
mongorm.New(&ToDo{}).Where(ToDoFields.ID.Eq(*todo.ID)).Delete(ctx)
}
Full documentation is in the docs/ folder.
| Topic | Description |
|---|---|
| Getting Started | Installation, model definition, schema setup |
| Configuration | Struct tags, options struct, mixed mode |
| Creating Documents | Inserting with Save() |
| Finding Documents | Querying with First() / Find(), Count(), and Distinct() |
| Updating Documents | Single and bulk updates |
| Deleting Documents | Removing documents |
| Bulk Write | Batch insert/update/replace/delete operations |
| Indexes | Field-based index builders and geo index setup |
| Aggregation | Aggregation pipelines with fluent builder and typed decoding |
| Cursors | Iterating with FindAll() |
| Query Building | Where(), find modifiers, pagination helpers, Set(), Unset() |
| Primitives | Type-safe field query methods |
| Hooks | Lifecycle hooks |
| Transactions | Running operations in MongoDB transactions |
| Errors | Sentinel errors and handling patterns |
| Timestamps | Automatic CreatedAt / UpdatedAt |
| Utility Types | Pointer helpers |
Quick map of commonly used entry points and where they are documented:
New(), FromOptions(), NewClient() → ConfigurationSave(), Update(), SaveMulti(), Delete(), DeleteMulti(), First() / Find() → Creating Documents, Finding Documents, Updating Documents, Deleting DocumentsWhere(), WhereBy(), Sort(), Limit(), Skip(), Projection(), After() / Before(), PaginateAfter() / PaginateBefore(), Set(), Unset() → Query BuildingFindOneAs[T, R](), FindAllAs[T, R]() → Finding DocumentsCount(), Distinct(), DistinctFieldAs[T, V](), DistinctStrings(), DistinctInt64(), DistinctBool(), DistinctFloat64(), DistinctObjectIDs(), DistinctTimes() → Finding DocumentsAggregate(), AggregateRaw(), AggregateAs[T, R](), AggregatePipelineAs[T, R]() plus stage builders → AggregationNewBulkWriteBuilder[T](), BulkWrite(), BulkWriteInTransaction(), EnsureIndex*() helpers → Bulk Write, IndexesFindAll(), MongORMCursor.Next(), MongORMCursor.All(), Document(), JSON() → Cursors, Utility TypesWithTransaction(), IsTransactionUnsupported(), sentinel errors (ErrNotFound, ErrDuplicateKey, ErrInvalidConfig, ErrTransactionUnsupported, ErrOptimisticLockConflict) → Transactions, ErrorsHTML documentation is available at html_docs/index.html.
Go MongoDB ORM, Golang MongoDB ORM, type-safe MongoDB query builder for Go, Go generics ORM, MongoDB CRUD library for Go, MongoDB transactions in Go, MongoDB aggregation in Go, MongoDB bulk write Go, MongoDB hooks and timestamps, lightweight Go ORM.
Use these when publishing the repository to maximize discoverability in GitHub search and community feeds.
go, golang, mongodb, orm, mongo-orm, golang-library, backend, query-builder, type-safe, generics, aggregation, transactions, bulk-write, developer-tools, data-access
v1.0.0 as the first stable release using .github/RELEASE_TEMPLATE.md.ctx := context.Background()
err := mongorm.New(&ToDo{}).EnsureGeoDefaults(
ctx,
ToDoFields.Location,
[]bson.E{mongorm.Asc(ToDoFields.CreatedAt)},
)
if err != nil {
panic(err)
}
See LICENSE.