mongodb/mongo-go-driver — 8.5k★ on GitHub (Go). The Official Golang driver for MongoDB
Snapshot summary built from the project's own GitHub metadata — there's no written TopGit review yet. The page will update automatically when a full review is published.
WHY NO REVIEW YET
TopGit writes full reviews for the most-starred, most-requested repositories. This page is a snapshot until then — see the READ ME tab for the original README in full.
See the following resources to learn more about upgrading from version 1.x to 2.0.:
v2.0 Migration Guide
v2.0 What's New
The MongoDB Go Driver follows semantic versioning for its releases.
Requirements
Go 1.25 or higher. The Go Driver supports the last two Go minor versions.
Go 1.26 or higher is required to run the driver test suite.
MongoDB 4.4 and higher.
Installation
The recommended way to get started using the MongoDB Go Driver is by using Go modules to install the dependency in
your project. This can be done either by importing packages from go.mongodb.org/mongo-driver and having the build
step install the dependency or by explicitly running
go get go.mongodb.org/mongo-driver/v2/mongo
Usage
To get started with the driver, import the mongo package and create a mongo.Client with the Connect function:
Several query methods return a cursor, which can be used like this:
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
defer cancel()
cur, err := collection.Find(ctx, bson.D{})
if err != nil {
log.Fatal(err)
}
defer cur.Close(ctx)
for cur.Next(ctx) {
var result bson.D
if err := cur.Decode(&result); err != nil {
log.Fatal(err)
}
// do something with result....
}
if err := cur.Err(); err != nil {
log.Fatal(err)
}
For methods that return a single item, a SingleResult instance is returned:
var result struct {
Value float64
}
filter := bson.D{{"name", "pi"}}
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
defer cancel()
err := collection.FindOne(ctx, filter).Decode(&result)
if errors.Is(err, mongo.ErrNoDocuments) {
// Do something when no record was found
} else if err != nil {
log.Fatal(err)
}
// Do something with result...
Additional examples and documentation can be found under the examples directory and on the MongoDB Documentation website.
Network Compression
Network compression will reduce bandwidth requirements between MongoDB and the application.
The Go Driver supports the following compression algorithms:
Snappy (snappy): available in MongoDB 3.4 and later.
Zlib (zlib): available in MongoDB 3.6 and later.
Zstandard (zstd): available in MongoDB 4.2 and later.
Specify Compression Algorithms
Compression can be enabled using the compressors parameter on the connection string or by using ClientOptions.SetCompressors:
If compressors are set, the Go Driver negotiates with the server to select the first common compressor. For server configuration and defaults, refer to networkMessageCompressors.
Messages compress when both parties enable network compression; otherwise, messages remain uncompressed
Support / Feedback
For issues with, questions about, or feedback for the Go Driver, please look into our support channels, including StackOverflow.
New features and bugs can be reported on the GODRIVER Jira project.
Contribution
Check out the GODRIVER Jira project for tickets that need completing. See our contribution guidelines for details.
Continuous Integration
Commits to master are run automatically on evergreen.
Frequently Encountered Issues
See our common issues documentation for troubleshooting frequently encountered issues.
Thanks and Acknowledgement
The Go Gopher artwork by @ashleymcnamara
The original Go Gopher was designed by Renee French
License
The MongoDB Go Driver is licensed under the Apache License.
How active is development on mongodb/mongo-go-driver?
The most recent commit recorded on mongodb/mongo-go-driver was 3 months ago, based on the GitHub push timestamp. The repository has 945 forks — one of the better signals of community interest.
How many stars does mongodb/mongo-go-driver have?
mongodb/mongo-go-driver has 8.5k GitHub stars — refresh the page for the live number, or check github.com/mongodb/mongo-go-driver. TopGit mirrors GitHub's count but does not claim minute-by-minute accuracy.
What else is in the Data space?
mongodb/mongo-go-driver is tracked by TopGit under the Data category, alongside 6 GitHub-tagged topics. Trending and Topics pages list peer repositories of comparable stars and language.
What language is mongodb/mongo-go-driver written in?
mongodb/mongo-go-driver is written primarily in Go. GitHub's language field is based on the largest share of bytes in the default branch.
What topics is mongodb/mongo-go-driver associated with?
GitHub's repository topics for mongodb/mongo-go-driver: "database", "driver", "go", "golang", "golang-library", "mongodb". TopGit's editorial category is Data.
Where do I read more about mongodb/mongo-go-driver?
This TopGit page is a snapshot — the READ ME tab shows the project's own README content (links stripped, images preserved). The GitHub repository at github.com/mongodb/mongo-go-driver is the definitive source.
Why is mongodb/mongo-go-driver categorized under Data?
TopGit places mongodb/mongo-go-driver in the Data category based on its GitHub topics and description (tagged: "database", "driver", "go"). Categories are assigned from real repository metadata, not editorial guesswork.
Read full README in the tab above.
Still deciding about mongo-go-driver?
One click hands the question to an AI along with this page — see what it says about mongo-go-driver.