MongoDB is a NoSQL database, which differs from traditional relational databases such as MySQL, Oracle, and Microsoft SQL Server.
The main difference between MongoDB and traditional databases is that MongoDB stores data in documents instead of tables. Documents are collections of key-value pairs, similar to JSON objects. This allows MongoDB to store complex hierarchical data with ease. For example, a MongoDB document might look like this:
{
“name”: “John Smith”,
“age”: 35,
“address”: {
“street”: “123 Main St.”,
“city”: “New York”,
“state”: “NY”,
“zip”: 10001
},
“hobbies”: [“hiking”, “biking”, “swimming”]
}
Traditional databases typically require the data to be structured in a tabular format. This means that the data must be divided into rows and columns, which limits the types of data that can be stored. In contrast, MongoDB’s document-based structure allows for more flexibility in terms of data types, making it easier to store and query complex data.