Introduction to MongoDB
MongoDB is an open source, document based, NoSQL database that maintains dynamic schema. You can maintain more than one database on a MongoDB server.
A MongoDB database contains a set of collections. A collection is a set of documents and is similar to a table in a relational database. MongoDB stores records as documents that are similar to rows in a relational database. A document contains fields that are similar to columns in a relational database. A document can have a dynamic schema. A document in a collection does not need to have the same set of fields or structure as another document in the same collection. A document can also contain nested documents.
The following schema provides a sample MongoDB document from the collection called Product:
{
sku: "111445GB3",
title: "CM Phone",
description: "The best in the world.",
manufacture_details: {
model_number: "CMP",
release_date: new ISODate("2011-07-17T22:14:15.656Z")
},
shipping_details: {
weight: 350,
width: 10,
height: 10,
depth: 1
},
quantity: 99,
pricing: [
{region: "North America",
cost_price: 1000,
sale_price: 1200},
{region: "Europe",
cost_price: 1200,
sale_price: 1500}
]
}
In the example, sku, title, description, quantity, manufacture_details, shipping_details, and pricing are fields. The fields manufacture_details and shipping_details are nested document type fields and pricing is an array type field.