Using Tigris as an open source MongoDB Atlas alternative for Go applications
Tags: mongodb, tigris, go, database
Published: 2023-02-28 12:24:14

---
title: Using Tigris as an open source MongoDB Atlas alternative for Go applications
published: true
date: 2023-02-21 00:00:00 UTC
tags: mongodb,tigris,golang,database
canonical_url: https://www.tigrisdata.com/blog/tigris-mongodb-atlas-alternative
---

MongoDB is one of the most popular databases developers use for data persistence for their applications. MongoDB has several benefits over traditional relational databases. One of the most significant advantages is its flexible data model, which makes it easier for developers to manage their data.

[MongoDB Atlas](https://www.mongodb.com/atlas) is the cloud-hosted version of MongoDB, including other proprietary data services such as Search and Analytics. While Atlas provides several benefits, there are three major issues associated with it: costs, control over data, and operational issues when dealing with large datasets.

In this blog post, we discuss Tigris as a scalable, cost-effective, and open source alternative to MongoDB Atlas. We will also demonstrate using the [Go driver for MongoDB](https://github.com/mongodb/mongo-go-driver) in a way that is transparent to the application that the data is stored in Tigris Cloud database.

The [Tigris Go MongoDB quickstart code](https://github.com/tigrisdata-community/go-mongo-quickstart)is available on GitHub.

## How Tigris differentiates from MongoDB Atlas[​](#how-tigris-differentiates-from-mongodb-atlas "Direct link to How Tigris differentiates from MongoDB Atlas")

At Tigris Data, we have built a [developer data platform called "Tigris"](https://github.com/tigrisdata/tigris) that provides a scalable, cost-effective, and open source alternative to MongoDB Atlas. Below are the key differentiators:

- Unlike MongoDB, Tigris follows [a modern composable architecture](https://www.tigrisdata.com/docs/concepts/architecture/)with loosely coupled components. Furthermore, compute is separated from storage, allowing for independent scaling and a more resilient system.
- The storage layer in Tigris is built on FoundationDB, and Tigris inherits the [strong consistency guarantees](https://www.tigrisdata.com/blog/building-a-database-using-foundationdb/#foundationdbs-correctness-and-fault-tolerance), and the scalability of FoundationDB.
- Tigris provides automatic database sharding, and shard keys are unnecessary as the data distribution is automatically handled. This ensures true serverless behavior with no painful transition from a non-sharded to a sharded MongoDB cluster.
- Tigris' open source Kubernetes-native design allows it to be deployed [anywhere in the cloud](https://www.tigrisdata.com/docs/concepts/platform/self-host/) in the user's account, ensuring that the user is always in control of their data.
- Some other differentiating features include global interactive ACID transactions, consistent secondary indexes, and an integrated search platform.

Now that we have gone over the key differentiators when comparing Tigris to MongoDB Atlas, let's look at a quickstart application that demonstrates performing CRUD operations on Tigris using the Go driver for MongoDB.

## Connect a Go application to Tigris using the Go driver for MongoDB[​](#connect-a-go-application-to-tigris-using-the-go-driver-for-mongodb "Direct link to Connect a Go application to Tigris using the Go driver for MongoDB")

This is a simple Go application that uses the Go driver for MongoDB through [FerretDB](https://github.com/FerretDB/FerretDB) in a way that is transparent to the application that the data is stored in Tigris.

The application demonstrates CRUD operations and is adapted from the excellent [blog series](https://www.mongodb.com/blog/post/quick-start-golang--mongodb--modeling-documents-with-go-data-structures) by Nicolas Raboy.

### Prerequisites[​](#prerequisites "Direct link to Prerequisites")

- A Tigris Cloud account. [Create one for free](https://console.preview.tigrisdata.cloud/signup).
- [Go](https://golang.org/) installed on your computer, and a working knowledge of Go.
- [Git](https://git-scm.com/downloads).
- Tigris CLI. The installation instructions can be found [here](https://www.tigrisdata.com/docs/sdkstools/cli/installation/).

### Setup[​](#setup "Direct link to Setup")

Clone the repo:

```
git clone https://github.com/tigrisdata-community/go-mongo-quickstart.git
```

Change into the directory where you cloned the repo:

```
cd go-mongo-quickstart
```

### Create the Tigris project and generate the application key[​](#create-the-tigris-project-and-generate-the-application-key "Direct link to Create the Tigris project and generate the application key")

Login to Tigris Cloud:

```
tigris login
```

Create a Tigris project and generate the application key. The project name will be used as the MongoDB database name. The application key is used to authenticate to Tigris.

```
tigris create project go_mongo_quickstart
tigris create app_key default --project go_mongo_quickstart
```

The above command will have an output similar to the following:

```
{
  "id": "your_client_id",
  "name": "default",
  "secret": "your_client_secret",
  "created_at": 1676857746000,
  "created_by":
  "google-oauth2|1111xxx",
  "project": "go_mongo_quickstart"
}
```

### Setup the `.env` file[​](#setup-the-env-file "Direct link to setup-the-env-file")

This application uses environment variables to store the URI, application key, and project name. Using the `id`, `secret`, and `project` values from the output above, create a file named `.env` with the following content:

```
TIGRIS_URI=m1k.preview.tigrisdata.cloud:27018
TIGRIS_PROJECT=go_mongo_quickstart
TIGRIS_CLIENT_ID=your_client_id
TIGRIS_CLIENT_SECRET=your_client_secret
```

### Running the quickstart[​](#running-the-quickstart "Direct link to Running the quickstart")

Run this quickstart application using the following command:

```
go run main.go
```

You will see output similar to the following:

```
Connected.
Inserted document into podcast collection: ObjectID("63f7e90863877e55d8e9ddf4")
Inserted 2 documents into episode collection!
Found 1 documents matching filter!
[
    {
        "ID": "63f7e90b63877e55d8e9ddf6",
        "Podcast": "63f7e90863877e55d8e9ddf4",
        "Title": "Progressive Web Application Development",
        "Description": "Learn about PWA development with Tara Manicsic.",
        "Duration": 32
    }
]
Updated 1 Documents!
DeleteOne removed 1 document(s)
```

### Explore the data[​](#explore-the-data "Direct link to Explore the data")

You can explore the data created by the quickstart application in Tigris Cloud Console

![Tigris Cloud Console screenshot](https://www.tigrisdata.com/blog/assets/images/go_mongo_quickstart_wc-49f61f9b6cf42fb231c91a8162b0d16f.png)

* * *

**Tigris is the open source MongoDB Atlas alternative.** Offers native support for ACID transactions, automatic database sharding, global secondary indexes, full-text search, high availability, data security, and database branching.

[![Hands on a laptop](https://www.tigrisdata.com/blog/assets/images/hand-laptop-08df8ce107a739b1f0fb27f84b07b85b.png)](https://console.preview.tigrisdata.cloud/signup)

Checkout the [quickstarts](https://www.tigrisdata.com/docs/quickstarts/), give us a star on [Github](https://github.com/tigrisdata/tigris), and join us on [Discord](https://www.tigrisdata.com/discord/).