What is a Document Database?
You might think it’s obvious what a document database is. It’s a database of documents, right?
Well, not exactly – at least not in the way you might think.
Also known as document-oriented databases, or document stores, document databases are non-relational databases that store data in flexible documents instead of fixed rows and columns.
It might surprise you to learn that document databases are the most popular alternatives to tabular, relational databases, but you’ll soon understand why. Document databases are simple, sensible, and super effective when it comes to organizing data.
Read on to learn more.
What are these documents?
In this context a document is a record which typically stores information about one object and any of its related metadata.
Data in the document is stored in a field-value pair, but the value can take several different structures like strings, numbers, dates, arrays or objects.
Some common formats are JSON, BSON, and XML. You might have come across a record like this when looking at information for a website
user. It would most likely contain their name, their contact information, maybe some preference information.
How are these documents organized?
Documents that have similar contents – for example documents that all record information about website users – are grouped together into collections.
Within a collection, not all documents need to have the same fields, thanks to document databases’ flexible schema.
How do developers use document databases?
Typically document databases have a query language, or an API, that developers can use to execute CRUD operations.
Create – documents can be created in the database, each with a unique identifier; Read – documents can be read from the database by querying for documents’ unique identifier or field values using the API; Update – either part of or all of a document can be updated; Delete – developers can delete documents from a database.
This combined with the flexible schema means document databases are easy to work with and keep up to date, and this can be a key benefit of non-relational databases.
What makes a document database a document database?
Document databases are defined as databases which use the document model, have a flexible schema, are distributed and resilient, and query through an API or querying language.
They are distinct from relational databases in a number of ways.
Firstly, the data model is much more intuitive, so it is more natural to work with. You don’t need to decompose data across tables or work out an Object Relational Mapping layer.
Secondly, JSON documents are pretty much everywhere now. JSON is now the established standard for data interchange and storage, because JSON documents are lightweight, easily readable by humans, and language independent. They allow developers to use them with data structure in whatever way their application needs.
Thirdly, their schema is flexible – it’s dynamic and self-describing. That means developers don’t have to do any extra work pre-defining the schema in the database. The structure can be modified at any time and can be different in different documents.
Why are document databases so popular?
Given all of these factors, it’s not too hard to see why these are an attractive alternative to relational databases.
Whereas relational databases might require several tables to store information about a user’s contact information, what they like, and the things they’ve done, a document database is able to handle all of those bits of data in one single document.
If you’re looking for an intuitive and easy to learn way to manage your data, document databases are probably the ideal solution. And because of their flexibility and adaptability, they’re likely to only become more and more common.
Find out more about the innovations that could change the way you work in our technology section.