MongoDB Go Driver
The MongoDB supported driver for Go.
Requirements
- Go 1.10 or higher. We aim to support the latest supported versions of go.
- MongoDB 2.6 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/mongo
When using a version of Go that does not support modules, the driver can be installed using dep
by running
dep ensure -add "go.mongodb.org/mongo-driver/mongo"
Usage
To get started with the driver, import the mongo
package and create a mongo.Client
with the Connect
function:
import (
"go.mongodb.org/mongo-driver/mongo"
"go.mongodb.org/mongo-driver/mongo/options"
"go.mongodb.org/mongo-driver/mongo/readpref"
)
ctx, cancel := context.WithTimeout(context.Background(),
…