DEV.co
Open-Source Databases · qiniu

qmgo

Qmgo is a Go driver for MongoDB that wraps the official mongo-go-driver with a simpler, mgo-like API. It provides CRUD operations, transactions, hooks, and aggregation with minimal code changes for teams migrating from the legacy mgo library.

Source: GitHub — github.com/qiniu/qmgo
1.4k
GitHub stars
151
Forks
Go
Primary language
Apache-2.0
License (OSI-approved)

Key facts

Objective fields from the source. Values we can't verify are shown as “Unknown” rather than guessed.

FieldValue
Repositoryqiniu/qmgo
Ownerqiniu
Primary languageGo
LicenseApache-2.0 — OSI-approved
Stars1.4k
Forks151
Open issues52
Latest releasev1.1.10 (2025-07-05)
Last updated2026-06-20
Sourcehttps://github.com/qiniu/qmgo

What qmgo is

Built on top of MongoDB's official Go driver, Qmgo abstracts connection pooling, cursor management, and query building into a chainable API. It supports transactions with retry logic, lifecycle hooks (BeforeInsert, AfterInsert), automatic field management (createAt, updateAt, _id), and validation tags via go-playground/validator.

Quickstart

Get the qmgo source

Clone the repository and explore it locally.

terminalbash
git clone https://github.com/qiniu/qmgo.gitcd qmgo# follow the project's README for install & configuration

Need it deployed, integrated, or customized instead? DEV.co ships production installs.

Best use cases

Migrating from mgo to official MongoDB driver

Qmgo is explicitly positioned as the minimal-friction path from legacy mgo codebases to the new mongo-go-driver. Existing mgo query patterns translate directly, reducing refactor scope.

CRUD-heavy backend services in Go

Ideal for REST/gRPC backends needing straightforward document CRUD, sorting, filtering, and pagination. Chain-call syntax reduces boilerplate compared to raw driver usage.

Transactional document workflows

Built-in transaction support with callback pattern, timeout, and retry logic simplifies multi-document ACID semantics without manual session management.

Implementation considerations

  • Requires Go 1.10+; MongoDB server 2.6+. Verify your Go version and MongoDB deployment versions before integration.
  • Connection initialization via qmgo.Open() or qmgo.NewClient(); always defer Close(ctx) to avoid resource leaks.
  • Struct tags (bson:"fieldname") must match MongoDB field names; use DefaultField or CustomFields() for automatic timestamp/ID injection.
  • Hooks (BeforeInsert, AfterInsert, etc.) are optional but useful; context must flow through all operations for transaction support.
  • Validation via go-playground/validator tags; ensure validation rules align with business logic before production deployment.

When to avoid it — and what to weigh

  • Requiring cutting-edge MongoDB server features — Latest release is v1.1.10 (2025-07-05). Unknown whether all MongoDB 6.0+ and 7.0+ server features are fully supported; requires version compatibility check.
  • Need for advanced ODM/ORM patterns — Qmgo is a thin convenience layer, not a full ORM. Complex schema modeling, relationship management, and validation workflows may require custom code or a heavier framework.
  • High-performance, latency-sensitive systems — No performance benchmarks provided in README. Abstraction overhead vs. raw driver unknown; not recommended for microsecond-level SLA systems without profiling.
  • Projects with zero MongoDB experience — Assumes familiarity with MongoDB query syntax, bson types, and transaction semantics. Documentation focus is mgo migrants, not MongoDB newcomers.

License & commercial use

Apache License 2.0 (Apache-2.0). A permissive open-source license allowing commercial use, modification, and distribution with attribution and liability disclaimer.

Apache-2.0 is a permissive OSI-approved license that explicitly permits commercial use, provided license and copyright notices are retained. No license fees or proprietary restrictions apply. However, consult your legal team for enterprise deployments to confirm compliance with internal policies.

DEV.co evaluation signals

Editorial assessment — not user reviews. Directional, with an explicit confidence level.

SignalAssessment
MaintenanceActive
DocumentationAdequate
License clarityClear
Deployment complexityLow
DEV.co fitStrong
Assessment confidenceHigh
Security considerations

Qmgo inherits MongoDB driver security practices (TLS support via URI options, auth methods). Sensitive data in BSON documents is not encrypted at the driver level; rely on MongoDB server-side encryption or application-layer encryption. Input validation must use validator tags or custom logic—no automatic injection prevention. MongoDB network isolation and authentication remain operator responsibility.

Alternatives to consider

Official mongo-go-driver

More verbose but gives direct control and guaranteed compatibility with all MongoDB features. Use if your team is MongoDB-fluent and accepts more boilerplate.

mgo (legacy)

Only if staying on older Go/MongoDB versions. No longer maintained; security and compatibility gaps likely. Qmgo is the recommended migration path.

sqlc / GORM with MongoDB adapter

If you need a unified ORM across SQL and NoSQL. More overhead; overkill for MongoDB-only workloads but useful for polyglot backends.

Software development agency

Build on qmgo with DEV.co software developers

Qmgo cuts boilerplate and eases mgo migration. Assess fit for your backend with a technical review, then contact us to architect your MongoDB integration.

Talk to DEV.co

Related open-source tools

Surfaced by semantic similarity across the DEV.co open-source index.

Related on DEV.co

Explore the category and the services that help you build with it.

qmgo FAQ

Is Qmgo production-ready?
Yes, it is actively maintained and used by Qiniu. Latest release (v1.1.10) is recent. Verify MongoDB server compatibility and run your own load tests.
Can I migrate from mgo with minimal code changes?
Yes, that is Qmgo's primary design goal. Query patterns, chain calls, and basic CRUD translate directly. Transactions and advanced mgo features may require adaptation.
Does Qmgo support MongoDB Atlas?
Yes, via standard MongoDB connection URIs. Pass your Atlas cluster URI to qmgo.Open() or qmgo.NewClient().
What is the performance overhead vs. raw mongo-go-driver?
Unknown. README provides no benchmarks. Qmgo is a thin wrapper; overhead is likely negligible for CRUD-heavy workloads but should be profiled for latency-critical systems.

Software development & web development with DEV.co

Adopting qmgo is usually one piece of a larger software development effort. As a software development agency, DEV.co provides software development services and web development expertise — pairing senior software developers and web developers with your team to design, build, and operate open-source databases software in production.

Ready to simplify your MongoDB workflow in Go?

Qmgo cuts boilerplate and eases mgo migration. Assess fit for your backend with a technical review, then contact us to architect your MongoDB integration.