.. _go-language-center:

.. include:: /includes/unicode-checkmark.rst

=================
MongoDB Go Driver
=================

.. default-domain:: mongodb

.. contents:: On this page
   :local:
   :backlinks: none
   :depth: 1
   :class: twocols

Introduction
------------

This is the official MongoDB Go Driver.

- `General documentation for the MongoDB Go Driver <https://godoc.org/go.mongodb.org/mongo-driver/mongo>`__

- `Get Started with Go <https://www.mongodb.com/blog/post/mongodb-go-driver-tutorial>`_

- `Migration from Community Drivers <https://www.mongodb.com/blog/post/go-migration-guide>`_

- `Changelog <https://github.com/mongodb/mongo-go-driver/releases>`__

- `Source Code <https://github.com/mongodb/mongo-go-driver>`__


Installation
------------

The recommended way to get started using the MongoDB Go driver is by using
`Go modules <https://blog.golang.org/v2-go-modules>`__


.. code-block:: go

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


See `Installation <https://github.com/mongodb/mongo-go-driver#installation>`__


Connect to MongoDB Atlas
------------------------

.. include:: /includes/atlas-connect-blurb.rst

.. code-block:: go

   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 <https://github.com/mongodb/mongo-go-driver#usage>`__
for more detail.


Compatibility
-------------

MongoDB Compatibility
~~~~~~~~~~~~~~~~~~~~~

.. include:: /includes/mongodb-compatibility-table-go.rst

Language Compatibility
~~~~~~~~~~~~~~~~~~~~~~

.. include:: /includes/language-compatibility-table-go.rst

.. include:: /includes/help-links-go.rst
