All stories
Java

Introduction to Mongo DB

H
hemant-kumar

July 23, 2012


Mongo DB is an open source document-oriented No SQL database system.

No SQL Database System
1.    It does not use SQL as its query language.
2.    It may not give full ACID guarantees.

RDBMS vs. Mongo

RDBMS
Mongo
Table, View
Collection
Row(s)
JSON Document (actually BSON)
Index
Index
Join
Embedded Document
Partition
Shard
Partition Key
Shard Key

Mongo DB data model

1.    Mongo system: Collection of databases.
2.    Database: Set of collections.
3.    Collection: Set of documents.
4.    Document: Set of fields.
5.    Field: Key-Value pair.
· Key    :  Name (String).
· Value :  String, integer, float, timestamp, binary, document, Array of values.

Mongo DB Basic Components

1.    Database Server : mongod.exe
2.    Interactive Shell : mongo.exe
3.    Sharding Router : mongos.exe

JSON
It stands for JavaScript Object Notation.

Example:
{     _id : "109",name : "hemant kumar",  hobbies : [ ”chess",”comics" ]    }

BSON
·    It stands for Binary JSON.
·    BSON is a binary representation of JSON
·    Mongo DB stores data in BSON

Documents
Mongo DB is a document based database. This means that we store data as documents.

Sample documents in Interactive shell with its equivalent code in java.

var a = {name: "Hemant Kumar"}

BasicDBObject obj = new BasicDBObject("name","Hemant Kumar");

var n = {name: 'Hemant Kumar', languages: ['c', ‘mongodb’, 'java']}

BasicDBObject obj = new BasicDBObject("name","Hemant Kumar");
ArrayList<String> list = new ArrayList<String>();
list.add("c");
list.add("mongodb");
list.add("java");
obj.append("languages",list);

var t = { name:'Hemant Kumar', info: { lang:['c', ‘mongodb’, 'java']  }  }

BasicDBObject obj = new BasicDBObject("name","Hemant Kumar");
ArrayList<String> list = new ArrayList<String>();
list.add("c");
list.add("mongodb");
list.add("java");
obj.append("info",new BasicDBObject("lang",list));
Java

0

If you found this helpful, give it some claps!

SHARE THIS ARTICLE

Share on X
LinkedIn

Responses0

Sign in to join the conversation

Sign in