API Reference

MongoDB Go Driver

The official MongoDB driver for Go, with client pooling, BSON support, and change streams.

Official Documentation ↗
CompatibilityThis documentation covers version v1.16. Check the official docs for the latest API surface.

Installation

gogo get go.mongodb.org/mongo-driver/v2

Methods

The driver connects to MongoDB, binds BSON documents to Go structs, and supports transactions.

Key Features

  • Client-side and server-side pooling
  • BSON marshalling with struct tags
  • Change streams and transactions

Usage Notes

Pin a version and check the official docs for the API surface you depend on before upgrading.

Security notes

Quoted verbatim from the official documentation; this is not a complete threat model. 来源:https://www.mongodb.com/docs/drivers/go/current/ · 取证方式:HTTP GET 官方 README/文档页(HTML 去标签) · 抓取时间:2026-11-07T13:50:59.353Z.

FAQ

How should the client be managed?
Create one Client per process or per cluster and reuse it; it is safe for concurrent use.
When are writes acknowledged?
Depending on write concern. The default is acknowledged, so InsertOne returns after a successful write.
How do I use transactions?
Start a session, call StartTransaction, run operations with the session context, then commit or abort.