Sitemap
Vithusika Thivakar

Vithusika Thivakar

Mongo DB

--

What is the Mongo DB?

MongoDB is a source-available cross-platform document-oriented database program. Classified as a NoSQL database program, MongoDB uses JSON-like documents with optional schemas. MongoDB is developed by MongoDB Inc. and licensed under the Server Side Public License

It is categorized under the NoSQL (Not only SQL) database because the storage and retrieval of data in MongoDB are not in the form of tables. The MongoDB database is developed and managed by MongoDB.

Inc under SSPL(Server Side Public License) and initially released in February 2009. It also provides official driver support for all the popular languages like C, C++, Java, Node.js, Perl, PHP, and Python. So, you can create an application using any of these languages.

MongoDB is a popular database used for developing full-stack web applications using MERN and MEAN stack.

What is NoSQL?

NoSQL is also known as “not only SQL”. They are non-tabular databases. They store data in a different manner than SQL databases. These kinds of databases come in various types based on their data model, such as document, key-value, wide-column, and graph. They are more flexible, scalable, distributed databases. Most of the NoSQL databases are open source.There are mainly four types of NoSQL database systems that exist. Each of them uses different types of data models.

Document databases
Graph databases
Key-value stores
Wide-column stores

Advantages of NoSQL

  • Handle large volumes of data at high speed with a scale-out architecture.
  • Store unstructured, semi-structured, or structured data.
  • Enable easy updates to schemas and fields.
  • Be developer-friendly.
  • Take full advantage of the cloud to deliver zero downtime

.The workload for interactive real-time web applications is simplified.
.NoSQL caters to flexibility for data that is not normalized and requires flexible data models.
.They provide great scalability for large data sets.
.They are greatly suited for cloud applications, mobile, and big data requirements.

Disadvantages of NoSQL

  • Not all NoSQL databases contemplate the atomicity of instructions and the integrity of the data. They withstand what’s know as eventual consistence.
  • Compatibility issues with SQL instructions. …
  • Lack of standarization. …
  • Cross-platform support. …
  • Poor usability

. NoSQL has its own querying languages. Which is in contrast to SOL.
. As NoSQL databases are newer, there are no standards as relational databases.
.There is no such schema as relational databases have.

Advantages of MongoDB

  • Schema less − MongoDB is a document database in which one collection holds different documents. Number of fields, content and size of the document can differ from one document to another.
  • Structure of a single object is clear.
  • No complex joins.
  • Deep query-ability. MongoDB supports dynamic queries on documents using a document-based query language that’s nearly as powerful as SQL.
  • Tuning.
  • Ease of scale-out − MongoDB is easy to scale.
  • Conversion/mapping of application objects to database objects not needed.
  • Uses internal memory for storing the (windowed) working set, enabling faster access of data.

Why Use MongoDB?

  • Document Oriented Storage − Data is stored in the form of JSON style documents.
  • Index on any attribute
  • Replication and high availability
  • Auto-Sharding
  • Rich queries
  • Fast in-place updates
  • Professional support by MongoDB

Where to Use MongoDB?

  • Big Data
  • Content Management and Delivery
  • Mobile and Social Infrastructure
  • User Data Management
  • Data Hub

The use Command

MongoDB use DATABASE_NAME is used to create database.

Get Vithusika Thivakar’s stories in your inbox

Join Medium for free to get updates from this writer.

The command will create a new database if it doesn’t exist, otherwise it will return the existing database.

Syntax

Basic syntax of use DATABASE statement is as follows −

use DATABASE_NAME

Example

If you want to use a database with name <student>, then use DATABASE statement would be as follows −

>use student
switched to db student

To check your currently selected database, use the command db

>db
student

If you want to check your databases list, use the command show dbs.

>show dbs
local 0.78125GB
test 0.23012GB

Your created database (student) is not present in list. To display database, you need to insert at least one document into it.

>db.movie.insert({"name":"tutorials point"})
>show dbs
local 0.78125GB
student 0.23012GB
test 0.23012GB

The dropDatabase() Method

MongoDB db.dropDatabase() command is used to drop a existing database.

Syntax

Basic syntax of dropDatabase() command is as follows −

db.dropDatabase()

The createCollection() Method

MongoDB db.createCollection(name, options) is used to create collection.

Syntax

Basic syntax of createCollection() command is as follows −

db.createCollection(name, options)

The drop() Method

MongoDB’s db.collection.drop() is used to drop a collection from the database.

Syntax

Basic syntax of drop() command is as follows −

db.COLLECTION_NAME.drop()

MongoDB — Datatypes

  • String − This is the most commonly used datatype to store the data. …
  • Integer − This type is used to store a numerical value. …
  • Boolean − This type is used to store a boolean (true/ false) value.
  • Double − This type is used to store floating point values.

--

--