6 - Document Databases With MongoDB
6 - Document Databases With MongoDB
database as a NoSQL.
This week we will learn how to implement a document database with MongoDB. Let us
start.
MongoDB is a document database.
The name comes from the English word ''humongous'', which means "enormous".
MongoDB saves data structures in BSON type documents, binary JSON, with their
dynamic schema, making the integration of data in certain applications easier and
faster.
MongoDB supports other queries, indexing, and replication.
In the case of other queries, MongoDB supports search by fields, rank, queries, and
regular expressions.
Queries can return a specific field of the document, but can also be a JavaScript
function defined by the user.
In the case of indexing, any field in a MongoDB document can be indexed, just as
secondary indexes are possible.
In the case of replication, MongoDB supports the type of master-slave replication,
which means the master can execute, read, and write comments,
and the slave can copy the data from the master, and can only be used for reading.
In the case of service failures with the current master, the slave has the ability to
choose a new master.
MongoDB is more suitable for information systems such as electronic commerce or e-
commerce, games, mobile applications, and content management like storage of
comments, votes, user registration, user profiles, and data sessions.
Now, in order to understand how MongoDB stores information, we need to learn some
concepts.
MongoDB saves data in JSON- type documents with a dynamic schema called BSON,
which implies that there is no predefined scheme.
The elements of the data are called documents, and are stored in collections.
A collection can have an indeterminate number of documents.
Collections are like tables, and documents like rows.
Each document in a collection can have different fields.
The structure of a document is simple and composed of key-value pairs, similar to the
associative matrices in a programming language.
As a value, you can use numbers, strings, or binary data as images or any other key-
value pairs.
In MongoDB, a document is a set of field value birth in JSON syntax.
The figure presents a visual example of a typical MongoDB document.
As we can see from the image, MongoDB provides a very flexible storage for the name,
age, and status, and groups of interests of a person.
It is also possible to grow up documents and say fixes, which are both having to
execute expansive joint operations.
The documents are analogous to the structure of the programming languages that
associate keys with values, such as hash tables, dictionaries, and maps.
Suppose two fields a and b, with values three are xyz.
The figure shows a JSON code for assigning values to a and b, and the corresponding
BSON representations.
Documents are stored in collections, which are a set of related documents that share
indexes.
The collections are analogous to the tables of the relational database.
The figure conceptually shows a collection of MongoDB.
Document storage offers high-performance, variables scalability, high flexibility,
and low implementation complexity.
Each document on MongoDB has an ID.
ID is the first attribute of the document, and the internal identifier is in hexadecimal
value.
In this example, we can see that the first four bytes are for a timestamp, the next three
bytes contain the matching identifier, next to bias contained a process identifier, and
the last three bytes are a counter.
MongoDB has a number of mongo-tools.
Some of them are briefly explained in the following sentences.
The binary Mongo is an interface that allows developers to view, insert, delete, and
update data in your database.
It helps also to replicate information, configure the shards, turn off the servers, and
execute JavaScript.
Mongostat is a command line tool that summarizes a list of statistics of our running
MongoDB instance.
Mongotop is a command line tool to track the amount of time it takes to read or write
data in an instance.
The mongosniff tool sniffs network traffic, going to and from MongoDB.
The binaries Mongo import, and Mongo export are command line tools that facilitate
the import and export operations for the content from JSON, CSV, or TSV.
Mongodump and mongorestore are tools for creating a binary export of the contents
of the database.
Well, now it's time for practice.
Next video we'll tell you the main steps to install and use MongoDB. See you then.