Skip to main content

Quickstart: Java

The following guide will get you up and running with Tigris. It covers data modeling, creating database and collection, writing queries to read and write data, and performing search all without touching any infrastructure.


All you'll need is any computer running macOS or Linux, with JDK 1.8 or newer installed.

Install Tigris CLI

Use the command below to install the CLI on macOS

brew install tigrisdata/tigris/tigris-cli

Alternative ways of installation can be found here.

Sign up for Tigris Cloud

You will need to have a Tigris Cloud account to complete this quickstart. If you don't already have an account, you can sign up for Tigris Cloud.

Login and set up the application credentials

Login to your Tigris Cloud account

tigris login

The next step is to create the project for the application we will be building

tigris create project quickstart

Now we can generate credentials to be used in this quickstart

tigris create app_key default "default key" -p quickstart

Once the command is executed, it would create the application credentials (clientID and clientSecret) and print it on the screen. Make a note of id and secret from the output.

"id": "your_client_id_here",
"name": "default",
"description": "default key",
"secret": "your_client_secret_here",
"created_at": 1666248043000,
"created_by": "google-oauth2|xxx",
"project": "quickstart"


Add the client library dependency to your project


For latest version and for other dependency management or build tool you can refer to dependency snippet from here

import com.tigrisdata.db.annotation.TigrisPrimaryKey;
import com.tigrisdata.db.client.Filters;
import com.tigrisdata.db.client.InsertResponse;
import com.tigrisdata.db.client.StandardTigrisClient;
import com.tigrisdata.db.client.TigrisClient;
import com.tigrisdata.db.client.TigrisCollection;
import com.tigrisdata.db.client.TigrisDatabase;
import com.tigrisdata.db.client.UpdateFields;
import com.tigrisdata.db.client.config.TigrisConfiguration;
import com.tigrisdata.db.client.error.TigrisException;
import com.tigrisdata.db.type.TigrisDocumentCollectionType;

import java.util.Objects;

public class TigrisApp {
public static void main(String[] args) throws TigrisException {
// configure the client
TigrisConfiguration config =
TigrisConfiguration.newBuilder("paste Tigris URI here")
new TigrisConfiguration.AuthConfig("paste client_id here", "paste client_secret here"))

// initialize the client
TigrisClient client = StandardTigrisClient.getInstance(config);

// create the database if it does not exist,
// and fetch the database object
TigrisDatabase helloDB = client.createDatabaseIfNotExists("hello-db");

// create the collections if they don't exist, or
// update the collection schema

// fetch the collection object, all the CRUD operations on the
// collection will be performed through this collection object
TigrisCollection<User> users = helloDB.getCollection(User.class);

// insert
User jania = new User("Jania McGrory", 6045.7);
User bunny = new User("Bunny Instone", 2948.87);

// read the auto-generated ids
int janiaId = jania.getUserId();
int bunnyId = bunny.getUserId();

// find the user by primary key field
User user = users.readOne(Filters.eq("userId", janiaId)).get();

// find user with Name Jania McGrory
User user = users.readOne(Filters.eq("name", "Jania McGrory")).get();

// update
Filters.eq("userId", janiaId),
.set("name", "Jania McGrover")

// transaction - transfer balance between users
(tx) -> {
try {
Filters.eq("userId", janiaId),
.set("balance", jania.getBalance() - 100)
Filters.eq("userId", bunnyId),
.set("balance", bunny.getBalance() + 100)
} catch (TigrisException tigrisException) {
// auto-rollback after throwing exception.
throw new IllegalStateException("Transaction failed", tigrisException);

// Search for users with `name` like "bunny" and `balance` greater than 500
SearchRequest request = SearchRequest.newBuilder()
.withFilter("balance", 500))
Iterator<SearchResult<User>> results =;
while (results.hasNext()) {
SearchResult<User> result =;

// delete users
users.delete(Filters.eq("userId", janiaId));
users.delete(Filters.eq("userId", bunnyId));

// drop the database and its collections

public static class User implements TigrisDocumentCollectionType {
@TigrisPrimaryKey(order = 1, autoGenerate = true)
private int userId;
private String name;
private double balance;

public User() {

public User(String name, double balance) { = name;
this.balance = balance;

public int getUserId() {
return userId;

public void setUserId(int userId) {
this.userId = userId;

public String getName() {
return name;

public void setName(String name) { = name;

public double getBalance() {
return balance;

public void setBalance(double balance) {
this.balance = balance;

public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
User user = (User) o;
return userId == user.userId
&&, balance) == 0
&& Objects.equals(name,;

public int hashCode() {
return Objects.hash(userId, name, balance);

Where to go from here?

🚀 Signup for Tigris Cloud - and start building your next application with it. We are here to help you get started. Join our Discord community to ask any questions you might have.