Basics Of MongoDB

Tharushi Dewangi
3 min readMar 6, 2021

--

INTRODUCTION

Today, the popularity of portable devices is growing at an incredible rate. Database Sizes for Small Applications Database sizes require more data than most databases can handle. As the amount of data that developers need to store increases, it becomes harder for developers to scale their databases. They either have to scale (i.e. get a bigger machine) or go out of scale (splitting data through more machines). Larger machines are more expensive so we can scale up to a certain limit and reach a physical limit where a more powerful machine cannot be purchased at any cost. So we have to go for a scale option for our databases.

Mongo DB has been designed to scale from the beginning. Its document-oriented data format allows data to be shared automatically across multiple servers. Balance data and load through clusters, automatically redistribute documents. Mongo DB seeks to simplify database administration

CHARACTERISTICS

General purpose database

Document type

High availability

Feature rich

Scalability and load Balancing

Aggregation framework

J/S /React support

Schema free based on binary Json,Bson

simple Query language

open source

Mongodb Vs RDBMC

collection VS table

Document VS row

Field VS column

INSTALL MONGODB IN WINDOWS

To install MongoDB on Windows, first download the latest release of MongoDB from https://www.mongodb.com/download-center

when MongoDB service successful installation

To begin using MongoDB, connect a mongo.exe shell to the running MongoDB instance. Either:

  • From Windows Explorer/File Explorer, go to C:\Program Files\MongoDB\Server\4.4\bin\ directory and double-click on mongo.exe.
  • Or, open a Command Interpreter with Administrative privileges and run:

“C:\Program Files\MongoDB\Server\4.4\bin\mongo.exe”

For more instruction go for

Commands

Show all databases
> show dbs
admin 0.000GB
config 0.000GB
local 0.000GB
test 0.000GB

create new table or use existing table

> use newdb
switched to db newdb
>

create collection

> db.newdb.insert({“Name”:”Test”})
WriteResult({ “nInserted” : 1 })
>

delete DB

> db.dropdatabase()

add collection

> db.createCollection(“samsung”)
{ “ok” : 1 }
> db.createCollection(“Apple”)
{ “ok” : 1 }

show existing collections

> show collections
Apple
newdb
samsung
>

Insert a single document

> db.samsung.insert({“name”:”j2",”chipset”:”A12",”RAM”:”4GB”})
WriteResult({ “nInserted” : 1 })
>

Insert Multiple documents

> db.htc.insert([{“name”:”htcc”,”ram”:”4GB”},{“name”:”htc1",”ram”:”4GB”},{“name”:”htc2",”ram”:”4GB”}])
BulkWriteResult({
“writeErrors” : [ ],
“writeConcernErrors” : [ ],
“nInserted” : 3,
“nUpserted” : 0,
“nMatched” : 0,
“nModified” : 0,
“nRemoved” : 0,
“upserted” : [ ]
})
>

--

--

Tharushi Dewangi
Tharushi Dewangi

Written by Tharushi Dewangi

Final Year Software Engineering Undergraduate Student in SLIIT https://github.com/TharushiNDewangi

No responses yet