MongoDb on Cloud

1-click AWS Deployment    1-click Azure Deployment

Overview

MongoDB is an open-source document database and leading NoSQL database. MongoDB is written in C++.MongoDB is a cross-platform, document-oriented database that delivers, high performance, high accessibility, and easy scalability. MongoDB works on notion of collection and document.

When you look at the data storage, you will find MongoDB storing data as JSON-like documents, i.e., from document to document, fields can vary. Also, the data structure can be changed over time.The document model of it maps to the objects in your application code, making data easy to work with.
Database
Database is a physical container for collections. Each database gets its own set of files on the file system. A single MongoDB server typically has multiple databases.
Collection
Collection is a group of MongoDB documents. It is the equivalent of an RDBMS table. A collection exists within a single database. Collections do not enforce a schema. Documents within a collection can have different fields. Typically, all documents in a collection are of similar or related purpose.
Document
A document is a set of key-value pairs. Documents have dynamic schema. Dynamic schema means that documents in the same collection do not need to have the same set of fields or structure, and common fields in a collection’s documents may hold different types of data.

MongoDB Architecture
The main purpose of designing MongoDB was to meet the demands of the modern-day apps and this is made possible with the unique architecture of it.

MongoDB Architecture
The MongoDB architecture provides you with the document data model that is the best way to work with data.

Easy: You can work with data in a natural and intuitive way.
Fast: You get great performance from it without much effort.
Flexible: It adapts to the environment easily and makes quick changes.
Versatile: It supports a wide variety of data and queries.
Availability: It delivers data globally over resilient apps through sophisticated replication and self-healing recovery.
Scalability: By using the native sharding, data grows horizontally.
Workload Isolation: It can run operational and analytical workloads in the same cluster.
Locality: You can place your data on particular devices and in a specific geographical location, for governance, class of service, and low-latency access.
Another important feature of MongoDB architecture is that it has a unified experience that gives you the freedom to run your applications anywhere.

Portability: In MongoDB, the same database can run everywhere.
Cloud Agnostic: Users can leverage a multi-cloud strategy without any bound.
Global Coverage: It is available as a service in 50+ regions from the major public cloud providers, such as AWS, Azure, etc.
With these capabilities and resources, you can build an Intelligent Operational Data Platform, promoted by MongoDB.

Why MongoDB?
There are many databases like SQL and others, but why MongoDB? By now, we already know that MongoDB is a NoSQL database, and that’s the same reason why we need to learn it.

These are some facts that have made MongoDB popular:

Aggregation Framework
BSON Format
Sharding
Ad-hoc Queries
Indexing

Aggregation Framework
Users can use the aggregation framework in a very efficient manner in it. For aggregation operations, MapReduce can be used. When large datasets process and generate results with the help of parallel and distributed algorithms on clusters, it is called MapReduce.

MapReduce itself consists of two sets of operations, which are: map() and reduce(). Let’s see what these are:

map(): Map is used to perform operations like filtering datasets and then performing sorting on those filtered datasets.
reduce(): After map() is performed, the operation of summarizing all the data is done by reduce().

BSON Format
BSON stands for Binary JSON, and it is JSON-like storage. MongoDB uses BSON, which is a binary-encoded serialization of JSON-like documents while storing documents in collections.As a primary key, the BSON format uses _id. As _id is used as a primary key, it should have a unique value associated with it, which is called ObjectId. The ObjectId is either generated by the application driver or the MongoDB service.

Sharding:
Sharding is a complicated process and is done with the help of several shards. Each shard holds some part of the data and functions as a separate database. Merging all the shards together forms a single logical database. Operations over here are performed by query routers.

Ad-hoc Queries
MongoDB supports range query, MongoDB regular expression, and many other types of searches. The queries in it include user-defined JavaScript functions and they return specific fields from the documents. By indexing BSON documents, it can support ad-hoc queries.

Indexing
MongoDB index is used to improve the performance of searches. Any field in a MongoDB document can be indexed as either primary or secondary. This lets the database engine to efficiently resolve the queries.

How does security in MongoDB work?
Security of data is paramount and therefore it is very much important to exercise control over access to the database. Though there is a long list of ways in which you can do this, but some of the important tips to help you secure your data are mentioned below :

Do not connect your DB to the Internet – Restrict the access to your database and do not connect it to internet if not required. It will protect your database from being hacked.
Enable firewall – You can restrict the entities from accessing your MongoDB server by enabling powerful firewalls. For your benefit allow the application servers to access the database. Different platforms allow diverse measures for securing the database. For more information check the MongoDB documentations and refer to the scenario that matches with yours.
Enable authentication – One of the best options is to deploy the MongoDB server on a trusted network. For better results configure auth as true. See below: auth = true.
Role-based authorization – you can control the activities of individual users by enabling role-based authentication. Instead of giving admin access to all the users, role-based authentication restricts the illegal access and protects the database at the end.
Use SSL – Until and unless you enable SSL the data is left unencrypted and prone to unauthenticated access. Hence if the MongoDB server is deployed on a untrustworthy network, enabling SSL is the best way to secure your database.
Data in MongoDB has a flexible schema.documents in the same collection. They do not need to have the same set of fields or structure, and common fields in a collection’s documents may hold different types of data.

Some considerations while designing Schema in MongoDB
Design your schema according to user requirements.

Combine objects into one document if you will use them together. Otherwise separate them (but make sure there should not be need of joins).

Duplicate the data (but limited) because disk space is cheap as compare to compute time.

Do joins while write, not on read.

Optimize your schema for most frequent use cases.

Do complex aggregation in the schema.

Example
Suppose a client needs a database design for his blog/website and see the differences between RDBMS and MongoDB schema design. Website has the following requirements.

Every post has the unique title, description and url.
Every post can have one or more tags.
Every post has the name of its publisher and total number of likes.
Every post has comments given by users along with their name, message, data-time and likes.
On each post, there can be zero or more comments.
In RDBMS schema, design for above requirements will have minimum three tables.

MongoDB supports many datatypes. Some of them are −

String − This is the most commonly used datatype to store the data. String in MongoDB must be UTF-8 valid.

Integer − This type is used to store a numerical value. Integer can be 32 bit or 64 bit depending upon your server.

Boolean − This type is used to store a boolean (true/ false) value.

Double − This type is used to store floating point values.

Min/ Max keys − This type is used to compare a value against the lowest and highest BSON elements.

Arrays − This type is used to store arrays or list or multiple values into one key.

Timestamp − ctimestamp. This can be handy for recording when a document has been modified or added.

Object − This datatype is used for embedded documents.

Null − This type is used to store a Null value.

Symbol − This datatype is used identically to a string; however, it’s generally reserved for languages that use a specific symbol type.

Date − This datatype is used to store the current date or time in UNIX time format. You can specify your own date time by creating object of Date and passing day, month, year into it.

Object ID − This datatype is used to store the document’s ID.

Binary data − This datatype is used to store binary data.

Code − This datatype is used to store JavaScript code into the document.

Regular expression − This datatype is used to store regular expression.

Working with RockMongo

RockMongo is a MongoDB administration tool using which you can manage your server, databases, collections, documents, indexes, and a lot more. It provides a very user-friendly way for reading, writing, and creating documents. It is similar to PHPMyAdmin tool for PHP and MySQL.

Downloading RockMongo
You can download the latest version of RockMongo from here: https://github.com/iwind/rockmongo

Installing RockMongo
Once downloaded, you can unzip the package in your server root folder and rename the extracted folder to rockmongo. Open any web browser and access the index.php page from the folder rockmongo. Enter admin/admin as username/password respectively.

Working with RockMongo
We will now be looking at some basic operations that you can perform with RockMongo.

Creating New Database
To create a new database, click Databases tab. Click Create New Database. On the next screen, provide the name of the new database and click on Create. You will see a new database getting added in the left panel.

Creating New Collection
To create a new collection inside a database, click on that database from the left panel. Click on the New Collection link on top. Provide the required name of the collection. Do not worry about the other fields of Is Capped, Size and Max. Click on Create. A new collection will be created and you will be able to see it in the left panel.

Creating New Document
To create a new document, click on the collection under which you want to add documents. When you click on a collection, you will be able to see all the documents within that collection listed there. To create a new document, click on the Insert link at the top. You can enter the document’s data either in JSON or array format and click on Save.

Export/Import Data
To import/export data of any collection, click on that collection and then click on Export/Import link on the top panel. Follow the next instructions to export your data in a zip format and then import the same zip file to import back data.

Architecture Overview 
It explains how all the different parts of the driver fit together. From the different language runtimes, through the extension and to the PHP libraries on top. This new architecture has replaced the old mongo extension. We refer to the new one as the mongodb extension.

 

At the top of this stack sits a pure » PHP library, which we will distribute as a Composer package. This library will provide an API similar to what users have come to expect from the old mongo driver (e.g. CRUD methods, database and collection objects, command helpers) and we expect it to be a common dependency for most applications built with MongoDB. This library will also implement common » specifications, in the interest of improving API consistency across all of the » drivers maintained by MongoDB (and hopefully some community drivers, too).
Sitting below that library we have the lower level driver. This extension will effectively form the glue between PHP and our system libraries (» libmongoc and » libbson). This extension will expose an identical public API for the most essential and performance-sensitive functionality:
• Connection management
• BSON encoding and decoding
• Object document serialization (to support ODM libraries)
• Executing commands and write operations
• Handling queries and cursors
By decoupling the driver internals and a high-level API into an extension and PHP libraries, respectively, we hope to reduce our maintainence burden and allow for faster iteration on new features. As a welcome side effect, this also makes it easier for anyone to contribute to the driver. Additionally, an identical public API will make it that much easier to port an application across PHP runtimes, whether the application uses the low-level driver directly or a higher-level PHP library.
» GridFS is a great example of why we chose this direction. Although we implemented GridFS in C for our old mongo driver, it is actually quite a high-level specification. Its API is just an abstraction for accessing two collections: files (i.e. metadata) and chunks (i.e. blocks of data). Likewise, all of the syntactic sugar found in the old mongo driver, such as processing uploaded files or exposing GridFS files as PHP streams, can be implemented in pure PHP. Provided we have performant methods for reading from and writing to GridFS’ collections – and thanks to our low level extensions, we will – shifting this API to PHP is win-win.
v

Data Modelling in MongoDB
The data in MongoDB has a flexible schema. Unlike in SQL databases, where you must have a table’s schema declared before inserting data, MongoDB’s collections do not enforce document structure. This sort of flexibility is what makes MongoDB so powerful.

When modeling data in Mongo, keep the following things in mind:

What are the needs of the application – Look at the business needs of the application and see what data and the type of data needed for the application. Based on this, ensure that the structure of the document is decided accordingly.
What are data retrieval patterns – If you foresee a heavy query usage then consider the use of indexes in your data model to improve the efficiency of queries.
Are frequent inserts, updates and removals happening in the database? Reconsider the use of indexes or incorporate sharding if required in your data modeling design to improve the efficiency of your overall MongoDB environment.

MongoDB is an open-source document database that provides high performance, high availability, and automatic scaling. Mongo DB has rapidly grown to become a popular database for web applications and is a perfect fit for Node.JS applications, letting you write Javascript for the client, backend and database layer.

MongoDB is owned by MongoDB (www.mongodb.com) and they own all related trademarks and IP rights for this software.

MongoDB is a famous open source provided by www.mongodb.org
This Image is made specially for Customers who are looking for deploying a self managed MongoDB Community edition on hardened kernel instead of just putting up a vanilla install.

Its schemaless nature is a better match to our constantly evolving data structures in web applications, and the integrated support for location queries is a bonus that’s hard to ignore.

MongoDb on Cloud for AWS

Features

 

FEATURES OF MONGODB

Details of Features are given below:

1. Indexing
Indexing uses to improve the performance of what you search in a database. You can index any field in a document with primary and secondary indices. Using index feature performance automatically increased.
2. Aggregation
In MongoDB, you can perform three ways to aggregation methods.
I. Aggregation Pipeline
II. Map reduce function
III. Single purpose aggregation.
Aggregation operations and batch processing you can use Map reduce, but aggregation pipeline delivers better performance for other aggregation operations.
3. Replication
MongoDB delivers high accessibility with replication sets and consists of two or more copies of the information. The role of primary or secondary nodes at any time in Replication. In Primary node, all writes and reads are done and in secondary nodes maintain a copy of the data of the primary using built-in replication.
4. Transactions
MongoDB 4.0 ha sadded multi-document ACID transactions support.
5. Ad hoc queries
Range query and regular expression search supports in MongoDB. In MongoDB, queries return specific fields of documents and also contain user-defined JavaScript functions.
6. File Storage
MongoDB used as a file system and its called Grid file system with load balancing and data replication features over multiple machines for storing files also included with MongoDB drivers. MongoDB disclosures function for file manipulation.
7. Load Balancing
MongoDB scales flat using sharding. You can choose a shard key, which determines how the data in a collection will be circulated. The data is split into ranges and circulated across multiple shards.
8. Capped Collection
MongoDB supports fixed-size collections and it’s called capped collections. This capped collection of collection maintains insertion order and once the definite size has been reached behaves like a circular queue.
For creating a capped collection you can use db.createCollection command.
9. Schema-less database
MongoDB is a schema-less database written in C++ because MongoDB database is more flexible than traditional database tables. In MongoDB no need for type mapping which removes an additional drain.
Other features of MongoDB :
1. In the MongoDB database, the rows don’t need to have a schema defined beforehand.
2. MongoDB allows representing hierarchical relationships or store arrays or other more complex structure within the data model.
3. MongoDB is a rich query language and it’s supporting all the CRUD (Create, Read, Update, and Delete) operations

Following are the Features of MongoDB
Indexing
Aggregation
Replication
Transactions
Ad hoc queries
File Storage
Load balancing
Capped Collection
Schema-less database

Details of Features are given below:

1. Indexing
Indexing uses to improve the performance of what you search in a database. You can index any field in a document with primary and secondary indices. Using index feature performance automatically increased.
2. Aggregation
In MongoDB, you can perform three ways to aggregation methods.
I. Aggregation Pipeline
II. Map reduce function
III. Single purpose aggregation.
Aggregation operations and batch processing you can use Map reduce, but aggregation pipeline delivers better performance for other aggregation operations.
3. Replication
MongoDB delivers high accessibility with replication sets and consists of two or more copies of the information. The role of primary or secondary nodes at any time in Replication. In Primary node, all writes and reads are done and in secondary nodes maintain a copy of the data of the primary using built-in replication.
4. Transactions
MongoDB 4.0 ha sadded multi-document ACID transactions support.
5. Ad hoc queries
Range query and regular expression search supports in MongoDB. In MongoDB, queries return specific fields of documents and also contain user-defined JavaScript functions.
6. File Storage
MongoDB used as a file system and its called Grid file system with load balancing and data replication features over multiple machines for storing files also included with MongoDB drivers. MongoDB disclosures function for file manipulation.
7. Load Balancing
MongoDB scales flat using sharding. You can choose a shard key, which determines how the data in a collection will be circulated. The data is split into ranges and circulated across multiple shards.
8. Capped Collection
MongoDB supports fixed-size collections and it’s called capped collections. This capped collection of collection maintains insertion order and once the definite size has been reached behaves like a circular queue.
For creating a capped collection you can use db.createCollection command.
9. Schema-less database
MongoDB is a schema-less database written in C++ because MongoDB database is more flexible than traditional database tables. In MongoDB no need for type mapping which removes an additional drain.
Other features of MongoDB :
1. In the MongoDB database, the rows don’t need to have a schema defined beforehand.
2. MongoDB allows representing hierarchical relationships or store arrays or other more complex structure within the data model.
3. MongoDB is a rich query language and it’s supporting all the CRUD (Create, Read, Update, and Delete) operations

Major Features of MongoDb

  • MongoDb supports rich query to fetch data from the database.
  • MongoDb supports replacing an entire document (database) or some specific fields with it’s update() command.
  • MongoDb supports Map/Reduce framework for batch processing of data and aggregation operation. Here is brief of how Map/Reduce works : MongoDb supports various programming languages like C, C# and .NET, C++, Erlang, Haskell, Java, Javascript, Perl, PHP, Python, Ruby, Scala (via Casbah).
  • It supports Server-side JavaScript execution. Which allows a developer to use a single programming language for both client and server side code.
  • MongoDb is easily installable.

AWS

Installation Instructions For Windows

Note: How to find PublicDNS in AWS

Step 1) RDP  Connection: To connect to the deployed instance, Please follow Instructions to Connect to Windows  instance on AWS Cloud

1) Connect to the virtual machine using following RDP credentials:

  • Hostname: PublicDNS  / IP of machine
  • Port : 3389

Username: To connect to the operating system, use RDP and the username is Administrator.
Password: Please Click here to know how to get password .

Step 2) Application URL: Access the application via a browser at  C:\Mongodb

Step 3) Other Information:
1. Default installation path: will be in your web root folder “  C:\Mongodb

2. Default ports:

  • Windows Machines:  RDP Port – 3389
  • Http: 80
  • Https: 443

3. It is free/unregister version for personal/commercial limited function.Trial features 51days left.

Configure custom inbound and outbound rules using this link

Installation Step by Step Screenshots

Azure

Installation Instructions of MongoDB 3.2 on Ubuntu

Note : How to find PublicDNS in Azure

Step 1) SSH Connection: To connect to the deployed instance, Please follow Instructions to Connect to Ubuntu instance on Azure Cloud

1) Download Putty.

2) Connect to virtual machine using following SSH credentials:

  • Hostname: PublicDNS  / IP of machine
  • Port : 22

Username: Your chosen username when you created the machine ( For example  Azureuser)
Password : Your Chosen Password when you created the machine ( How to reset the password if you do not remember)

Step 2) Application URL: Access the application via a browser at “http://PublicDNS/”

Step 3) Other Information:

2.Default installation path: will be “/var/www/html/”

3.Default ports:

  • MongoDB Port:-27017

4. To access Webmin interface for management please follow this link

Note: MongoDB server is running on port 27017.
Please use appropriate ACL to secure the port for external use.

Installation Instructions For MongoDB 3.4 on CentOS

Note : How to find PublicDNS in Azure

Step 1) SSH Connection: To connect to the deployed instance, Please follow Instructions to Connect to Centos instance on Azure Cloud

1) Download Putty.

2) Connect to virtual machine using following SSH credentials:

  • Hostname: PublicDNS  / IP of machine
  • Port : 22

Username: Your chosen username when you created the machine ( For example  Azureuser)
Password : Your Chosen Password when you created the machine ( How to reset the password if you do not remember)

Step 2) Application URL: Access the application via a browser at “http://PublicDNS/”

Step 3) Other Information:

1.Default installation path: will be “/var/www/html/”

2.Default ports:

  • MongoDB Port:-27017

4. To access Webmin interface for management please follow this link

Note: MongoDB server is running on port 27017.
Please use appropriate ACL to secure the port for external use.

Configure custom inbound and outbound rules using this link

For a list of installation instructions customized for your platform MongoDb.

Videos

Install MongoDB in Ubuntu

Mongodb install on Ubuntu 14 04

MongoDb on Cloud

Related Posts