Wednesday, January 7, 2015

MongoDB - JSON/BSON/Documents

MongoDB - Lesson 1 

These are my notes from MongoDB university free DBA class.

MongoDB works on concept of collection and document.

MySQL   |   MongoDB  
Database = Database
Table = Collection
Row = Document
Column = Field
Table Join = Embedded Documents
Primary Key = Default key _id provide by mongodb itself

MongoDB language is based on JSON Language. No Join / No complex transaction.

JSON

Example : Document/Row
{ _id :"A11",
x :"1",
y:"2",
z:{a,b} --embedding
}

Find id = A11

Example: query

db.collection.find({_id: "A11"})

JSON Types (Java Script Object Notation)

- Pure data exchange format
- Document-Oriented















Quiz : How many data types in Json ?

Ans : 6

  1. Strings
  2. Numbers
  3. Booleans(True\False)
  4. Null
  5. Arrays
  6. Objects/Documents
















Left hand side - Only String is a valid type

Quiz

















Ans:

Person
{"name" : "John",
  "Age" : 25,
 "Address" :
  {"city" : "New York",
     "PostalCode" : 10021
 }
"Phone" :
{"Home": "212-555-1234",
"Mobile": "646-555-1234"
}
}

Binary JSON

Fast Scannability
Data types

  1. Binary Data
  2. Object ID
BSON Format
-- Mongodb driver
















integer = 32 bit (4 bytes)

BSON and Applications
















No comments:

Post a Comment

How to add a Database to AlwaysOn Availability Group with four different options

To add a database to an existing AlwaysOn availability group, MS has given us four options to choose from Automatic seeding Full database an...