Skip to main content

Working Locally

Getting started working with Tigris locally requires one easy step.

Starting up Tigris on your local machine

Open your terminal, and:

tigris dev start

This will spin up Tigris locally via Docker. The Tigris server will then be available on port 8081.

Health Check

You can use the ping command to verify that the server is ready to accept requests.

tigris ping

Start building

That's it, you are ready to build with Tigris!

Create sample schema

For this quickstart we will model a simple ecommerce app. The data would be stored in three collections products, users and orders.

Let's use the CLI to generate the sample schema and create the three collections in the Tigris project named myproject.

tigris generate sample-schema --create

The schema of the collections created can be fetched as follows

tigris describe collection --project=myproject orders

Insert data

The following example will insert data into the users and products collections and then read it back.

One of the main features of Tigris is the ability to perform ACID transactions. We will perform a transaction that involves inserting and updating documents in the orders, users and products collections.

Now lets fire up the CLI and use the Tigris APIs to perform CRUD operations on the data.

Insert some data into the user and product collections

tigris insert --project=myproject users \
'[
{"id": 1, "name": "Jania McGrory", "balance": 6045.7},
{"id": 2, "name": "Bunny Instone", "balance": 2948.87}
]'
tigris insert --project=myproject products \
'[
{"id": 1, "name": "Vanilla Beans", "quantity": 6358, "price": 4.39},
{"id": 2, "name": "Cheese - Provolone", "quantity": 5726, "price": 16.74},
{"id": 3, "name": "Cake - Box Window 10x10x2.5", "quantity": 5514, "price": 36.4}
]'

Read the data that was inserted by the Primary key field

tigris read --project=myproject users '{"id": 1}'
tigris read --project=myproject products '{"id": 3}'

Read the data that was inserted by any field in the schema

tigris read --project=myproject users '{"name": "Jania McGrory"}'
tigris read --project=myproject products '{"name": "Vanilla Beans"}'

Perform a transaction that modifies all three collections

tigris transact --project=myproject \
'[
{
"insert": {
"collection": "orders",
"documents": [{
"id": 1, "user_id": 1, "order_total": 53.89, "products": [{"id": 1, "quantity": 1}]
}]
}
},
{
"update": {
"collection": "users", "fields": {"$set": {"balance": 5991.81}}, "filter": {"id": 1}
}
},
{
"update": {
"collection": "products", "fields": {"$set": {"quantity": 6357}}, "filter": {"id": 1}
}
}
]'

Search for a product

tigris search --project=myproject products -q "vanilla"

Shutting down the local Tigris

Shutting down the locally running Tigris is also as easy as requiring a single step. Open your terminal, and:

tigris dev stop

Customizing the Tigris server version and port

You can change the Tigris server port. For example, if you want the server to be available on port 9091:

tigris dev start 9091