Introduction to NoSQL Database with NosDB

In this ever-evolving world, advancement in technology is accelerating at an extremely fast pace. Traditional databases have become far too slow, presenting serious bottlenecks, both in terms of speed and storage capacity. Therefore, the advent of a much needed replacement, the introduction of NoSQL, was seen as a life saver by many serious players out there.
Delving into this market, Alachisoft has also introduced its very own NoSQL document database for .NET, NosDB, released under the Apache 2.0 license. NosDB is a key-value store which takes string based values as keys and stores objects in the form of JSON against them. Being fast and extremely scalable, it makes for a good substitute for those wanting to shift from the legacy database systems. You can get started with the product following these five quick steps:

Install NosDB in your Database Servers

To begin working with NosDB, you first need to download the setup and install it on your system. For a standalone database, you are required to host NosDB on a single machine but Alachisoft recommends a minimum of two database servers for production purposes so that the reliability and the scalability of your databases are preserved.

Listed below are the minimum system requirements recommended by NosDB. Although, they are not a compulsion, following them will help you make use of the product effectively:

  • Dual CPU (8-core) machine.
  • Minimum 16 GB of RAM.
  • Minimum 1 GB of network card.
  • Amount of disk storage required depends on your need since NosDB does not use up much memory.
  • Windows server 2012 R2 or later.
  • NET 4.5, 4.6 or 4.0.
  • PowerShell 4.0 or later.
  • Microsoft web deploy 3.5 or higher is needed for the REST API.

NosDB officially supports .NET and JAVA clients. You have the option of installing them on separate systems as well as with the database servers. Both of them can run on windows 2012 or 2008 and the JAVA one can also run on UNIX.

If you need any help installing the setup(s), you can refer to NosDB documentation.

Create Cluster and Database

Having successfully installed NosDB on your servers, you can now set up your environment to work within. If you have a standalone server, you can directly create a database on it. When working with more than one database servers, however, you need a way to connect them so that together they logically form a single database server. To achieve this goal, you need to first form a cluster, which would be a set of connected servers and then create databases upon it.

Create a Cluster

To make use of multiple servers effectively, NosDB supports ‘sharding’ and ‘replication’. With sharding, you could spread your data over a number of servers and thereby, increase the scalability of your system. Replication allows you to maintain multiple copies of the same data, making it more reliable.

There are two ways of creating a NosDB Cluster:

  • NosDB Management Studio
  • PowerShell

We make use of the NosDB Management Studio in the example below to create a standard sharded cluster consisting of two database servers:

  • In the Object Explorer section, you will find Databases Cluster. Right-click on it and choose creating a new cluster:

1

  • On the appearing window, fill in the Cluster Name and choose the desired Authentication mode. I’m opting for Windows Authentication. This mode will automatically consider the domain user authenticated. If, however, you opt for the NosDB Authentication, you will be required to provide a user-name and the password for it.

2

  • Clicking ‘Next’ will take you to another window which will configure a new shard for your database cluster:

3

  • Having created a shard, you need to add nodes to it. Every shard has one primary node which accepts all the write operations irrespective of the number of nodes you have in your shard. I have a single node here so this will be the primary node. If you have more than one node, you can assign them priorities. This will help NosDB decide which node to select as the primary:

4

  • If you are working with multiple servers, here is how you can add another node to the shard. You can, however, leave this step if you are working with a standalone database server.

5

  • Repeat this procedure for the other shard. The screen shot below shows how the summary will appear at the end:

6

Create a Database

Whether you are working with a stand-alone database or a cluster of database servers, your next step is to create a database to work upon. This can be done by either using the management studio or by working with PowerShell.

In order to demonstrate the use of PowerShell, we will use it to create a sample database:

    • You can use the Data Definition Language (DDL) to create a database. Invoking an SQL query follows the format below:
    • Using this format, we create a ‘northwind’ database and specify the following:
      • Multifile: A Boolean value that helps identify if your database should be able to save multiple files or not.
      • CacheSize: Specifies the size of the cache.
      • MaxCollections: Limits the maximum number of collections that can be made for this database.

Test the Database Cluster

Once your environment is set, you need to test if your database is working as desired. For that, you need to check the statisticsThis can be done in either of the following ways:

You can refer to the ‘Database Monitoring’ section in the documentation available online if you have trouble using any of the aforementioned techniques. Once you have set up your chosen method of observing database statistics, you now need to add some actual data in your database and test if it is working as expected. NosDB provides a tool dedicated for this task, the stress test tool. Follow the steps mentioned below to work with this tool:

  • Open PowerShell.
  • You can run this tool on a single database at a time. Here, I am selecting ‘northwind that I created in the beginning of this tutorial:
    PS NosDB: clusterdatabasesnorthwind
  • Now, you run the actual command along with a few specifications:
    TestStressThreadCount3ReportingInterval1000MaxDocuments100000
In the PowerShell command above, we have:
  • Test-Stress: It creates a test collection by the name of ‘nosdb_test_coll’ and multi-tasks on it(adds, removes or updates data from this database simultaneously).
  • ThreadCount: This indicates the number of client threads. Increasing the number of threads increases the load on the database.
  • ReportingInterval: Interval between the test case scenarios.
  • MaxDocuments: This indicates the maximum number of documents you can perform the test on. Default is 10,000.

Soon after you run this tool, you should be able to see numbers appear on your counters’ window.
8

  • You can also run a simple query from the management studio to check if your database returns the desired results.

9

Use Database with Applications

If your database has successfully passed the testing, it’s now time to use it with actual user applications. You can access NosDB from within .NET in the following three ways:

The following example shows how to perform CRUD operations without SQL:

Here, we demonstrate how to perform CRUD operations with the use of SQL:

Similarly, as mentioned above, NosDB provides support for LINQ and ADO.NET as well. You can refer to ‘Third Party Integrations’ section in the programmer’s guide, for details regarding their use.

Visual Studio Integration

You can perform all the NosDB related operations using Visual Studio as well by simply installing the NosDB Management Package extension. For details regarding the installation of this package, you may refer to the to ‘Third Party Integrations’ section in the programmer’s guide.

Once you have NosDB integrated with Visual Studio, you can get started with NosDB from within Visual Studio following the steps detailed below:

  • To open the NosDB Explorer, go to the Visual Studio menu bar and select VIEW -> Other Windows -> NosDB Explorer:

10

  • This will open the NosDB Explorer window containing a toolbar and a tree-like structure with all the related information needed:

11

  • You can execute whatever operations you feel like from here, now. The screen shot below shows how running a simple query will appear in Visual Studio:

12

In addition to this, NosDB offers Power BI integration as well. You can find the details regarding it under the “Using Microsoft Power BI with NosDB” section in the Administrator’s Guide for NosDB.

This walk-through shall get you started with the product. NosDB is easy to setup which comes with a rich feature set. Moreover, if you are a rigorous Windows user, NosDB is your best bet since it has been developed in .NET and is purely Windows based. You can refer to the documentation online to further explore the solution.

Leave a Reply

Your email address will not be published. Required fields are marked *