joplin-notes/joplin notion extension/Web Development/NOSQL/mongodb/Theory.md
2026-11-04 00:33:23 +05:30

33 lines
No EOL
1.8 KiB
Markdown

Theory
https://www.youtube.com/playlist?list=PL4cUxeGkcC9h77dJ-QJlwGlZlTd4ecZOA
- relational database
1 author can have many books whose information are stored in the other table named Books.
![9a6a085c63fcaeb121f425de0d03d4b0.png](../../../../_resources/9a6a085c63fcaeb121f425de0d03d4b0.png)
So we have rows,columns, table and joining
Columns is property
and we use sql queries to use them
- non relational database
Here instead of rows, columns and tables we use collections and documents
Each collection store a specific type of data record like users, authors and books.These records inside collections are called documents
So users is collection unlike table in sql. and instead of containing columns and rows it contains document which is more like js object
![2edcc32c60246452cda407c2da2e3c18.png](../../../../_resources/2edcc32c60246452cda407c2da2e3c18.png)
Here author field has nested object. in sql we would have to use other table for that.
**Installation**
- In arch use
`yay -S mongodb-bin` this will install mongodb server and mongodb shell. Make sure to start mongodb service too by
`systemctl start mongodb`
also install mongodb-tools. `mongodb-org-tools` in case of debian and `mongodb-tools-bin` from aur in case of arch. it is for import, export and other diagonistic tools
 
- in linux mint/ubuntu
https://www.mongodb.com/docs/v7.0/tutorial/install-mongodb-on-ubuntu/#std-label-install-mdb-community-ubuntu
**Collections and Documents**
![1a819c18ab7dea9f21918c9abcfae274.png](../../../../_resources/1a819c18ab7dea9f21918c9abcfae274.png)
Mongodb stores data in BSON which is Binary JSON and returns result in JSON.
Each document has a property `_id` which is assigned automatically by mongodb and its data type is 'ObjectId'.