Mongo Basic

NoSql– means not only sql. In this we are not going to use structured query language. It is different from relational database.

Why is need of NoSQL?

With the increase of internet usage the companies like google, amzon, ebay, facebook, twitter they get 2.5 quintillion byes of data. Referring url

So it required to handle such big-data big database and the data which is generated is in all forms like structured, unstructured or semi-structured so in rdbms it only handle structured data so how to handle semi and un-structured data that’s why there is need of NoSQL database. RDBMS failed to handle to large amount data.

Features of NoSQL database:

  1. It stores large volumes of structured, unstructured and semi structured data.
  2. High performance, high scalability and high availability.
  3. It provide quick iterations
  4. We can use object oriented programming in these databases.
  5. The support replication
  6. Auto-sharding – it means it converts large database into small, fast or easily manageable parts or chunks. Meaning of shard means small parts.
  7. Also support dynamic schemas.

Types on NoSQL databases: –

  1. Key-Value Stores: Redis, dynamo
  2. GraphDb- orientDB, Neo4j
  3. Column Oriented- BigTable, Cassandra
  4. Document Db- mongoDb and CouchDb

Difference between RDBMS and MongoDB

In RDBMS we have server à on which Database present à Database contains Tables à table contains rows. Every table in database tables have fixed schema means table structure. We use table to write complex joins and if table are big joins are expensive.

In MongoDb we have serverà on which database present à database contains collectionsà in collections contains documents à in document contains fields. In this collection is schema. Means no need to decide which kind of data enter into that document.

To start MongoDb go to installation directory and use run mongo.exe from command prompt.

C:\Program Files\MongoDB\Server\4.0\bin > this is path of installation directory which is default.

Then run Mongo.exe to start server.     

  1. Show dbs:  this command is used to show which database present on server.
  2. Use dbName: this command is used for if the database is present it switched to that database but If not present then it will create new database of that name which is provided in this command. After using use command but you can’t see a database is created for this you need to create one collection and add at least one row to that collection.
  3. To create collection use below command :
    1. db.departments.insert({Id:1,name:’Hr’})
  4. createCollecion: db.createCollection(“departmentDemo”) both command are used to create collection but first command create collection and insert one row in that collection and in second command you can create empty collection. In this command createCollection will take 2 parameters first is collection name and second is Options.
    • Name: is type of string and description is name of that collection
    • Options: is a document and description is used to specify indexing, memory size and maximum number of documents.  This is completely optional parameter.
      • i.Capped: it is collection which deletes old data automatically when it reaches it maximum size and it required size parameter also.
      • Max: max documents which enter.
    • db.createCollection(“employee”,{capped:true,size:3644,max:1000})
  5. Show collections: This command is used for to show the collection which are present in that respective database.
  6. Find: Is like select query  db.departments.find() this is used to select all fields with all documents in that collection.
  7. Pretty: db.departments.find().pretty() this command is used to better format of output of that command or find command which  executed.
  8. explain: this is used for explaining the query which you want explanations. db.departments.find().pretty().explain()
  9. insert: is used to insert document in collection db.departments.insert({Id:1,name:’Hr’})
  10. Save: one another method is to insert document in collection in below example we create one anonymous object and assign data to that properties and save that data into collection by using save method.

> var empinfo={};

> empinfo.Name=”sagar jaybhay”;

sagar jaybhay

> empinfo.salary=11000;

11000

> empinfo.department=”development”;

Development

empinfo.languages=[“Hindi”,”English”,”Marathi”];

> db.employee.save(empinfo);

db.employee.find().pretty()

  1. Drop database: to drop database you need to switch that database first by using use database name command and then use db.dropDatabase() to drop a database. Commands are case sensitive so write commands as it is.
  2. Drop Collection: db.collectionname.drop() this is the command without parameter. It is parameter less method and return true or false based on successful delete.
    1. db.employee.drop();

Sagar Jaybhay, from Maharashtra, India, is currently a Senior Software Developer at Software Company. He has continuously grown in the roles that he has held in the more than seven years he has been with this company. Sagar Jaybhay is an excellent team member and prides himself on his work contributions to his team and company as a whole.

Sagar Jaybhay

Sagar Jaybhay, from Maharashtra, India, is currently a Senior Software Developer at Software Company. He has continuously grown in the roles that he has held in the more than seven years he has been with this company. Sagar Jaybhay is an excellent team member and prides himself on his work contributions to his team and company as a whole.

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *