Saturday, July 6, 2019

MongoDB

Image result for mongodb



What is MongoDB-----:-

MongoDB is a document database with the scalability and flexibility that you want with the querying and indexing that you need

⧫    MongoDB stores data in flexible, JSON-like documents, meaning fields can vary from document to document and data structure can be changed over time

⧫ The document model maps to the objects in your application code, making data easy to work with

⧫ You can make developments easily


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

In sql data save as table Mongodb saves as collections.










Basic Commands for the MongoDB

Installation Commands (Ubuntu) :

#1
sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 9DA31620334BD75D9DCB49F368818C72E52529D4


#2
echo "deb [ arch=amd64 ] http://repo.mongodb.com/apt/ubuntu bionic/mongodb-enterprise/4.0 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-enterprise.list

#3
sudo apt-get update

#4
sudo apt-get install -y mongodb-enterprise


How to Start 




#Step 1: Start MongoDB  .
sudo service mongodb start
 #Stop MongoDB
sudo service mongodb stop
#  To Start the Server
sudo mongo
# To Start the Client
sudo mongod



Basic Commands 



1. Finding the current database you’re in 

db 

2. Listing databases

Show dbs



3. Go to a particular database
use Database_name

4. Creating a Database
use Database_name     :- use command used for both action

5. Creating a Collection
db.createCollection("myCollection")


6. Inserting Data
db.myCollection.insert({"name": "john", "age" : 22, "location": "colombo"})
 db.myCollection.insertOne(i      {       "name": "navindu",        "age": 22      })
 db.myCollection.insertMany([      {        "name": "navindu",         "age": 22      },         {        "name": "kavindu",  "age": 20      },    { "name": "john doe",  "age": 25,        "location": "colombo"}     ])
7. Querying Data
db.myCollection.find()
 db.myCollection.find().pretty()

8. Updating documents
db.myCollection.update({age : 20}, {$set: {age: 23}})
db.myCollection.update({name: "navindu"}, {$unset: age});

9. Removing a document
db.myCollection.remove({name: "navindu"});

10. Removing a collection
db.myCollection.remove({});




Some  Funtions















Connecting method With Database and server



Image result for mongodb

No comments:

Post a Comment

Express

In this tutorial, we will also have a look at the express framework. This framework is built in such a way that it acts as a minimal an...