mongo-go-driver
The Official Golang driver for MongoDB
The official Go library for connecting to and querying MongoDB databases, maintained by MongoDB, supporting document storage, network compression, and all current database features. Requires Go 1.19 or newer.
This is the official library that lets programs written in Go talk to a MongoDB database. MongoDB is a database that stores information as flexible documents (think structured text records) rather than the rows and columns of a traditional spreadsheet-style database. This library is maintained by MongoDB themselves, so it stays in sync with new database features.
A developer adds this library to their Go project and uses it to connect to a running MongoDB server, then perform operations like storing new records, searching for existing ones, updating data, or deleting it. The README walks through the basic steps: connect with a URL pointing at the database, get a reference to a specific collection (the MongoDB equivalent of a table), and then read or write documents.
The library also supports network compression, which shrinks the data sent back and forth between the application and the database server. Three compression formats are available: Snappy, Zlib, and Zstandard. Enabling one can reduce bandwidth use, which matters when the application and database are on separate machines.
This is version 2.0, which introduced breaking changes from the older 1.x line. The README links to a migration guide for developers upgrading. It requires Go version 1.19 or newer and MongoDB 4.2 or newer. The project is licensed under the Apache License and accepts community contributions through a public issue tracker. Bug reports and feature requests go through MongoDB's Jira system.
Where it fits
- Add MongoDB database access to a Go web server or REST API to store and retrieve records
- Search, update, and delete flexible document records from within a Go application
- Enable Snappy or Zstandard network compression to reduce bandwidth between a Go app and a remote MongoDB server
- Upgrade a project from the older mongo-go-driver 1.x to version 2.0 using the provided migration guide