Document Databases
- Schemaless
- Store data in documents and these documents are grouped into collection
- If you are familiar with relational databases we can say documents are analogous to rows and collections are analogous to table
Documents
- Set of key-value pairs
- Key: string
- Value: number, string, booleans, arrays, objects
- Polymorphic model it's means that documents within the same collection don't needt to have the same structure
- Formats: JSON, BSON, YAML, XML
JSON document format
{
"user_id": 512,
"name": "Carol",
"last_name": "Harper",
"email": "carolharper@datazy.com",
"address": {
"street": "123 Sesame Street",
"city": "New York City",
"state": "New York",
"country": "USA" },
"hobbies": [
"hiking", "painting"
]
}
The value of "address" key is another document, notice that is related information is embedded in the main document, so don't need for searching about address in another document
Collections
- Set of documents
- Store the same type of entities
Advantages of document databases
- Flexibility
- Don't need to predefine the schema
- Documents can vary over time => avoid schema migrations
- Embedded documents => avoid joins
Intuitive for developers
- Natural way to work
- JSON is human-readable
- Documents map objects in code
Horizontal scalability
Limitations of document databases
- More responsibility
- Care about data in the application code
- Care about redundant data
The most popular document databases is "Mongo DB"