What is a Document Database?

A document-oriented database or a NoSQL document store is a modern way to store data in JSON format rather than simple rows and columns. It allows you to express data in its natural form the way it's meant to be.

For the past 40 years, relational databases have dominated the database industry. Relational databases organize data in tables of rows and columns and generate relationships between them. These relationships are considered to be the logical connections between the tables and are defined on the basis of the data itself.

However relational databases were unable to cope up with the challenges stated below.

  • Agile software development requires adaptable processes and quicker shipment of software. This means the underlying database should enable this methodology. In contrast, rows and columns are inherently rigid data structure. One column addition impacts the whole table.
  • With relational databases, a change in the data model means a developer requests changes from a database administrator. This people-intensive process can take too long for emerging and growing companies that rely on speedy deployment.
  • Lastly, data expressed in rows and columns is an unnatural way to store information. The reason being, a row in an RDBMS is just a flat data structure, with data divided into columns, whereas, data schemas are much more complex therefore demand more flexibility.

NoSQL Document Oriented Database

With such problems faced by data intensive and fast moving organizations, new technology solutions were demanded and the answer is NoSQL Document Databases. In contrast to rows and columns, NoSQL databases keep data in documents. These documents follow a minimum of standard format rules (so that the database can understand it for post processing). The format used could be JSON, XML, YAML etc. The JSON format is the format of choice for NoSQL databases, and for good reason. A JSON document is simply more compact and more readable.

JSON (JavaScript Object Notation) is a data representation format formulated by the JavaScript programming language. But because of its textual nature it is also used by all other programming languages.

JSON in NoSQL: A Flexible, Fluid & Rich Data Model

The beauty of JSON lies in its ease of use, by both humans and computers. The JSON format has three basic foundations:

  • Key value pairs or attributes: Every value in JSON is stored in a key value pair. These pairs are sometimes referred to as attributes. The keys are simple strings and the values could be of any type e.g. int, float, double, boolean etc.
  • Embedding JSON objects: Other than primitive types, values in a key value pair can also be other JSON objects allowing you to create a hierarchy of JSON Objects. Placing JSON objects inside another JSON object is called an "embedded data model" in document databases.
  • Arrays: Arrays are a natural programming idiom in all programming languages and data structures, so why not store data the way it is expressed? The JSON format also supports storing arrays as values against a key.

To see all three basic foundations in a single document, please take a look at the following JSON document.

JSON document example

Here you can see that the JSON document holds primitive types as values as well as other JSON objects and array types. What's interesting is that values can also host arrays of JSON objects. Thus JSON documents allow you to create a hierarchy of embedded JSON objects to an unlimited level. It's completely up to the user what shape he or she wants to give to the data stored in a NoSQL document database.

RDBMS vs NoSQL Document Databases

With such great advantages of the JSON data format, let's re-visit the challenges relational databases face and how a document database overcomes them.

Accomodates Agile Software Development

Agile Software Development is a process built on principles which follow adaptive and evolutionary processes. Therefore, it is essential that all of the platforms taking part in the software process are responsive to the application changes required. NoSQL document databases are purpose built for this.

JSON documents are stored in a collection, a term identical to tables (that store rows and columns). At the time of inception of a collection there is no need to define the attributes. Thus if there is a need to change the schema, simply add new JSON documents following the new schema without affecting existing data.

Accomodates Faster Deployment Cycles

Document databases also eliminate the need for specific database modeling teams since the data schema is directly generated by the application. Therefore, document databases promote application driven data models. The .NET API of NosDB automatically generates the corresponding JSON schema with respect to the provided .NET objects. Thus it also eliminates the need for specific ORM libraries, making your applications lightweight.

Accomodates Rich Data Structures

In relational databases, you create relations between different tables and then perform JOIN queries repeatedly to obtain the same piece of information again and again. It would be faster to group these pieces of data together since they are repeatedly accessed together. JSON documents allow you to embed related documents allowing easy fetching of data in one single call. Therefore, storing data in the JSON format is truly a natural way to store information unlike the flat data structure of rows and columns.

Furthermore, breaking the fixed relations between tables allows NoSQL databases to easily distribute data across multiple machines, thus also distributing the read and write load. Distribution has its own set of advantages and is further discussed under the topic Why NoSQL.

Use NosDB - NoSQL Document Database for .NET

While document databases provide a new way to store data, it doesn't mean you have to learn a new method to access data. NosDB allows you to access JSON documents using standard SQL and LINQ and it hosts strong indexing capabilities. NosDB is integrated with the .NET stack including an ADO.NET provider and integration with PowerShell, Visual Studio and Microsoft PowerBI.

Signup for monthly email newsletter to get latest updates.

© Copyright Alachisoft 2002 - . All rights reserved.