Home >>MongoDB Tutorial >MongoDB Overview
MongoDB is a document-oriented, cross-platform database that offers high performance , high availability, and easy scalability. MongoDB works on set and document concepts.
The database is an actual collection container. On the file system, each database gets its own set of files. Usually, a single MongoDB server has several databases.
The collection is a group of documents from MongoDB. It is the equivalent of the table of an RDBMS. Inside a single database, a set exists. A schema is not implemented by collections. Documents may have different areas within a collection. In general, all documents in a collection have a common or related purpose.
A document is a set of pairs of key-values. The Dynamic Schema Documents. Dynamic schema means that records in the same collection do not need to have the same set of fields or structure, and different types of data may be kept in common fields in collection documents.
The relationship of RDBMS terminology with MongoDB is shown in the following table.
RDBMS | MongoDB |
---|---|
Database | Database |
Table | Collection |
Tuple/Row | Document |
column | Field |
Table Join | Embedded Documents |
Primary Key | Primary Key (Default key _id provided by MongoDB itself) |
mysqld/Oracle | mongod |
mysql/sqlplus | mongo |
The following example shows a blog site's document structure, which is simply a key value pair separated by a comma.
{ _id: ObjectId(7df78ad8902c) title: 'MongoDB Overview', description: 'MongoDB is no sql database', by: 'phptpoint', url: 'http://www.phptpoint.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 } ] }
The _Id is a hexadecimal number of 12 bytes that ensures the uniqueness of any document. When inserting the document, you can insert I d. MongoDB offers a unique ID for every document if you do not have one. These 12 bytes are the first 4 bytes for the current timestamp, the next 3 bytes for the machine I d, the next 2 bytes for the MongoDB server process I d, and the remaining 3 bytes are basic incremental values.