DEV Community

Phil Leggetter for Tigris Data

Posted on • Originally published at tigrisdata.com on

Using Tigris as an open source MongoDB Atlas alternative for Go applications

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 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 in a way that is transparent to the application that the data is stored in Tigris Cloud database.

The Tigris Go MongoDB quickstart codeis available on GitHub.

How Tigris differentiates from MongoDB Atlas

At Tigris Data, we have built a developer data platform called "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 architecturewith 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, 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 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

This is a simple Go application that uses the Go driver for MongoDB through 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 by Nicolas Raboy.

Prerequisites

  • A Tigris Cloud account. Create one for free.
  • Go installed on your computer, and a working knowledge of Go.
  • Git.
  • Tigris CLI. The installation instructions can be found here.

Setup

Clone the repo:

git clone https://github.com/tigrisdata-community/go-mongo-quickstart.git
Enter fullscreen mode Exit fullscreen mode

Change into the directory where you cloned the repo:

cd go-mongo-quickstart
Enter fullscreen mode Exit fullscreen mode

Create the Tigris project and generate the application key

Login to Tigris Cloud:

tigris login
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

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"
}
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

Running the quickstart

Run this quickstart application using the following command:

go run main.go
Enter fullscreen mode Exit fullscreen mode

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)
Enter fullscreen mode Exit fullscreen mode

Explore the data

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

Tigris Cloud Console screenshot


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

Checkout the quickstarts, give us a star on Github, and join us on Discord.

Top comments (0)