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.
- Download free version here and install.
- After installing open goto mongoDB installation directory using file explorer and goto bin and double click mongod to start.
- Now command prompt will open.If there werre no errors.You have successfully installed mongoDB.Now don't close the cmd just minimize.
- Now open another command window.
- type mongo and enter.
- Now you will find the mongoDB version you installed.
- type DB
- now you can see what is the working database.
- 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.
- Now my database is db1.
- now type "db.student.insert({"name":"John", "dob":ISODate("1995-01-20T00:00:00Z"), "subjects":["science","maths"] }); "
- This will insert a new student document to database and student called John.When adding date or time we have to use UTC format.
- To find a document we added, type "db.student.find({"name":"John"});".mongoDb is case sensitive.cannot use "john" instead of "John.
- To Add "English to subjects" type "db.student.update({"name":"John"},{$push:{"subjects":"English"}});".
- To find all student type "db.students.find();".
- to remove a specific student type "db.students.remove({"name":"John"});".
No comments:
Post a Comment