Basics of MongoDB:
Is a physical container for collections.
Each database gets its own set of files on the file system.
A single MongoDB server typically has multiple databases.
Is a group of MongoDB documents.
It is the equivalent of an RDBMS table.
A collection exists within a single database.
Collections do not enforce a schema.
Documents within a collection can have different fields.
Typically, all documents in a collection are of similar or related purpose.
Is effectively a JSON document with some additional features.
Is a set of key-value pairs.
Documents have dynamic schema.
Dynamic schema means that documents in the same collection do not need to have the same set of fields or structure, and common fields in a collection’s documents may hold different types of data.
MongoDB stores the documents in BSON (Binary JSON) format
– Supports length prefix on each value (Easy to skip over a field)
– Information about the type of a field value
– Additional primitives types not suppported by raw JSON like UTC date time, raw binary, and ObjectId
The data structure that defines a MongoDB document is called BSON (Binary JSON). BSON is binary representation of JSON and also supports data types such as Date, which is not supported in plain JSON format.
MongoDB internally converts JSON to BSON and vice versa for performance benefits, although the user can save, query and retrieve as JSON.
• Every document in Mongo must have an “_id” field that is unique
• Default ObjectId created by Mongo when you insert a document
“_id” : ObjectId(“56ce74c0b02806eff4558f1f”),
“name” : “Uthapizza”,
“description” : “Test”
ObjectId is a 12 byte field:
• id.getTimestamp() returns the timestamp in ISO Date format.
var id = new ObjectId();