Navigation

MongoDB Go Driver

Introduction

This is the official MongoDB Go Driver.

Installation

The recommended way to get started using the MongoDB Go driver is by using Go modules

mkdir goproj
cd goproj
go mod init goproj
go get go.mongodb.org/mongo-driver/mongo

See Installation for additional ways to add the driver to your project.

Connect to MongoDB Atlas

To connect to a MongoDB Atlas cluster, use the Atlas connection string for your cluster:

import "go.mongodb.org/mongo-driver/mongo"

ctx, _ := context.WithTimeout(context.Background(), 10*time.Second)
client, err := mongo.Connect(ctx, options.Client().ApplyURI(
   "mongodb+srv://<username>:<password>@<cluster-address>/test?w=majority"
))
if err != nil { log.Fatal(err) }

See Usage for more detail.

Compatibility

MongoDB Compatibility

Go DriverMongoDB 4.2MongoDB 4.0MongoDB 3.6MongoDB 3.4MongoDB 3.2MongoDB 3.0MongoDB 2.6
1.3
1.2
1.1
1.0

Language Compatibility

The MongoDB Go driver requires Go 1.10 or later.

How to get help