Chapter 3

Creating Your First Collection & Cluster

Creating Your First Collection & Cluster

Now that you have a better understanding of how commands in OstrichDB work. Lets create a collection to store some data.

From your OstrichDB command line, type the following command:

OST>>> NEW COLLECTION my_collection

This should successfully create a new collection called my_collection. In its current state you can view the collection from you file explorer. To do this

  1. Open your operating system’s file explorer.
  2. Navigate to the directory where you installed OstrichDB.
  3. Open the bin directory.
  4. Open the collections directory.

You should see a file called my_collection.ost. This is the file that stores the data for your collection.

If you open the newly created collection file you should only see about 7 lines of text. This is the metadata header that OstrichDB uses to ensure collections are properly formatted and thier data is stored correctly. DO NOT EDIT THIS FILE DIRECTLY! Doing so could cause data corruption and loss.

Now keeping that file open, return to your OstrichDB command line and type the following command:

OST>>> NEW CLUSTER my_cluster WITHIN my_collection

Now if you looks back to the collection file you should see a new line of text that looks something like this:

{
	cluster_name :identifier: MY_CLUSTER
	cluster_id :identifier: 445538880462173

},

If you are worried that you typed the cluster name incorrectly, dont worry! OstrichDB takes all user alphabetical input and converts it to uppercase for consistency. So my_cluster will always be MY_CLUSTER in the collection file.

Now lets test something out; back in your OstrichDB command line type the following command:

OST>>> FETCH COLLECTION my_collection

In your terminal this should display the following just like it looks in the file itself:

{
	cluster_name :identifier: MY_CLUSTER
	cluster_id :identifier: 445538880462173

},

Congratulations! You have successfully created your first collection and cluster in OstrichDB. But wait, theres no real data here. Lets add some data to the cluster.