Monday, May 1, 2017

MongoDB


MongoDB is an open source document based non relational database.It's the most popular non-relational database. It's an object relational database.Uses spider Monkey java script engine.


When to use mongoDB


  • Don't want a rigid schema.
  • Need horizontally salable performance for high loads.

Pros of MongoDB.

  • High performance - Nosql databases are built for performance,measured in terms of both throughput and latency.
  • scalability - can scale out on low cost. 
  • High availability.
  • schema less - If have a flexible schema, this is ideal for a document store like in mongoDB.
  • can choose what level of consistency we want depending of the value of the data.
  • free.
  • Can run on many platforms - linux,windows...

Cons.

  • less flexibility with quering- no joins.
  • no support for transactions.
  •  

Mongodb and MySQL terminology and concepts.


MySQL                 |            MongoDB

Table                                Collection
Row                                 Document
Columns                          Field
Joins                                Embedded documents,linking


How to install and do simple insert, update, find, remove.


  1. Download free version here and install.
  2. After installing open goto mongoDB installation directory using file explorer and goto bin and double click mongod to start.
  3. Now command prompt will open.If there werre no errors.You have successfully installed mongoDB.Now don't close the cmd just minimize.
  4. Now open another command window.
  5. type mongo and enter.
  6. Now you will find the mongoDB version you installed.
  7. type DB
  8. now you can see what is the working database.
  9. is you need to change or create a database type use <any name you want>.If db already exist, now  mongodb change it's working database to typed name. If no db for that name.it will create a new db.
  10. Now my database is db1.
  11. now type "db.student.insert({"name":"John", "dob":ISODate("1995-01-20T00:00:00Z"), "subjects":["science","maths"] }); "
  12. This will insert a new student document to database and student called John.When adding date or time we have to use UTC format.
  13. To find a document we added, type  "db.student.find({"name":"John"});".mongoDb is case sensitive.cannot use "john" instead of "John.
  14.  To Add "English to subjects" type "db.student.update({"name":"John"},{$push:{"subjects":"English"}});".
  15. To find all student type "db.students.find();".
  16. to remove a specific student type "db.students.remove({"name":"John"});".
This article covers basic operations like insert, update, delete, find.Using software like robomongo or mongochef we can easily do these operations.I hope you learnt something and Thank You.

No comments:

Post a Comment