MongoDB - Overview

MongoDB is a cross-platform, document-centric database that provides high performance, high availability, and ease of scaling. MongoDB is working on the concept of collection and document.
Database
The database is the physical container for the collections. Each database gets its own set of files in the file system. One MongoDB server usually has multiple databases.
Collection
A collection is a group of MongoDB documents. This is the equivalent of an RDBMS table. The collection exists in the same database. Collections don't enforce schema. Documents in a collection can have different fields. Typically, all documents in a collection have a similar or related purpose.
Document
A document is a set of key-value pairs. Documents have a dynamic schema. Dynamic schema means that documents in the same collection do not have to have the same set of fields or structure, and common fields in documents in a collection can contain data of different types.
The following table shows the relationship of DBMS terminology to MongoDB.
RDBMS | MongoDB |
---|---|
Database | Database |
table | Collection |
Tuple / Row | Document |
speaker | field |
Joining a table | Subdocuments |
Primary key | Primary key (default key _id provided by mongodb itself) |
Database server and client | |
Mysql / Oracle | mongod |
MySQL/SQLPLUS | mongo |
Sample Document
The following example shows the document structure of a blog site, which is simply a pair of key values ​​separated by commas.
{ _id : ObjectId ( 7df78ad8902c ) title : 'MongoDB Overview' , description : 'MongoDB is no sql database' , by : 'phpclassroom' , url : 'https://phpclassroom.com' , tags : [ 'mongodb ' , 'database' , 'NoSQL' ], likes : 100 , comments : [ { user : 'user1' , message : 'My first comment' , dateCreated : new Date ( 2011 , 1 , 20 , 2 , 15 ), like : 0 }, { user : 'user2' , message : 'My second comments' , dateCreated : new Date ( 2011 , 1 , 25 , 7 , 45 ), like: 5 } ] }
_id is a 12-byte hexadecimal number that makes each document unique. You can specify _id when inserting a document. If you don't provide, MongoDB will provide a unique ID for each document. These 12 bytes, the first 4 bytes for the current timestamp, the next 3 bytes for the machine id, the next 2 bytes for the process id of the MongoDB server, and the remaining 3 bytes are a simple incremental VALUE.