[Link] - [Link]
com/courses/M001/about
JSON is stored as BSON (Binary JSON)
JSON -> BSON
Simplicity - simple database
Data replication and reliability - allows users to replicate data on multiple
mirrored servers which ensures data reliabiliyt
Advantages -
- NoSQL queries
- Schema free migrations
- Open Source
MongoDB atlas - cloud based solution
Terminology
RDBMS NoSQL
Database Database
Tables Collection
Rows Documents (json)
Column Field
Table Join Embedded documents
Primary Primary Key supplied by MongoDB itself (ObjectId)
Q - ?
caching, in-memory solutons, faster performance?
mongoBD cmds -
> show dbs (shows all dbs i have)
admin 0.000GB
config 0.000GB
local 0.000GB
> db (what db i making use of right now)
test
> use mymongobatch (create a new db mymongobatch)
switched to db mymongobatch
> [Link]("associate") -- (create a new collection in db)
{ "ok" : 1 }
> show collections
associate
> [Link]();
true
> [Link]();
{ "ok" : 1 }
> [Link]({ "id":singh,"name":"rahul singh","designation":"Solution
Architect"})
WriteResult({ "nInserted" : 1 })
> [Link]({ "id":52134,"name":"Anurag","designation":"Software
Enginerr","team":"FreshDirect"})
> [Link]({}) -- same as insert.
> [Link]([{},{},{}...])
> [Link]()
{ "_id" : ObjectId("61e011b971fc2e80192e7da4"), "id" : singh, "name" : "rahul
singh", "designation" : "Architect" }
{ "_id" : ObjectId("61e0122571fc2e80192e7da5"), "id" : 52134, "name" : "Anurag",
"designation" : "Software Enginerr", "team" : "FreshDirect" }
--ObjectId created by mongodb - unique. u can also define ur own id/use ur id
> [Link]().pretty() (beautified json view)
> [Link]({"name":"rahul singh"}).pretty() -- select * from associate
where name="rahul singh";
> [Link]({"name":"rahul singh"},{"designation":1}).pretty() -- select
designation from associate where name="rahul singh";
> [Link]({"name":"rahul singh"},{"designation":1, _id:0}).pretty() --
hide a column, show remaing
more options - {price " {$lt: 100}}
> [Link]().limit(3) - first 3 records
> [Link]().skip(3) - skips first 3 records
> [Link]().sort({"name":1}) - sorts with name
> [Link]().sort({"name"-1}) - sorts in reverse order of name
> [Link]({"name":"Anurag"},{$set:{name:"Anurag Srivastava"}})
Capped Collections -
- Fixed size circular collections
- will start deleting the oldest documents
> [Link]("logs",{capped:true,size:10000,max:1000})
size - size of collection in bytes
max - max no of documents in collection
if any of the limit is reached, document will be removed in FIFO