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

No comments:
Post a Comment