MongoDB
MongoDB is a document database which belongs to a family of databases called NoSQL - not only SQL. In MongoDB, records are documents which behave a lot like JSON objects in JavaScript. Values in documents can be looked up by their field’s key. Documents can have some fields/keys and not others, which makes Mongo extremely flexible.
| Features | Relational (SQL) | Non-Relational (NoSQL) | |
|---|---|---|---|
| Data Type | Hard to store rich data type | Able to store literally any type of data | |
| Scaling | Not trivial to scale, and not cheap | Scaling is automatic and transparent | |
| Cost | Expensive to build and maintain | Around 10% cost to Relational DB | |
| Representation | Represents data in tables and rows | Represents data as collections of JSON documents | |
| Query | Structured Query Language (SQL): makes SQL injection attack possible | Object Querying: intuitive, passing a document to explain what you're querying for | |
| Multi-originated | JOIN operation: perform query across multiple tables | Multi-dimensional data type: support array and even other documents | |
| Atomic Style | Support Atomic Transaction: able to contain multiple operations with a transaction and roll back the whole thing if it were a single operation | Does not support Atomic Transaction, but single operations are atomic | |
| Schema | Require to define tables and columns before storing. Each row has same columns | No schema, drops in documents. Two documents in a collection can have different fields | |
| Perfomance | Poor performance when using ORM | Perform much better | |
| Application | Better when: Data structure fits nicely into table and rows. Or Require SQL or transactions | Better when: Data seems complex in relational database system. Or De-normalizing database schema or coding around performance. Or Can not pre-define schema or want to store records in same collection that have different fields | |
This is different than SQL databases like MySQL and PostgreSQL, where fields correspond to columns in a table and individual records correspond to rows.
5Steps to Run:
1.Download MongoDB
2.Extract the Path
3. Go as Cmd as Following Path :- cd Downloads/mongodb-osx-x86_64-4.0.2/bin/
4. Run : iMac:bin Santosh_imac$ mongod
2018-09-19T11:12:24.339+0530 I CONTROL [main] Automatically disabling TLS 1.0, to force-enable TLS 1.0 specify --sslDisabledProtocols 'none'
2018-09-19T11:12:24.491+0530 I CONTROL [initandlisten] MongoDB starting : pid=26402 port=27017 ...................................................................................................................
5.open another cmd Run in same path : bin santosh_imac$ mongo
MongoDB shell version v4.0.2
connecting to: mongodb://127.0.0.1:27017
MongoDB server version: 4.0.2
Server has startup warnings:
2018-09-19T11:12:35.781+0530 I CONTRO
6. > show dbs
=============================================================================================
=============================================================================================
7. Show Collections
8. db.collectionname.find()
9.db.createnamecollection.save({"name":"xyz"})
Comments
Post a Comment