When creating an application based upon a traditional RDBMS, you would normally define a plethora of tiny tables that are consulted when presenting the website user with HTML select options, radio buttons, or checkboxes. The only other alternative would be to hardcode such defaults and options into configuration files.
When using MongoDB, you can take advantage of two radical differences from a legacy RDBMS:
- Each document in a collection does not have to have the same schema.
- Documents can contain arrays.
The following table summarizes the options needs for Sweets Complete:
Item | Key | Value |
gender | M | Male |
F | Female | |
X | Other | |
social media | FB | |
TW |
As you can see, for these two items, a dictionary is defined with key–value pairs. For other items, summarized in the following table, there are lists for which there is no key:
Item | Values |
categories | Cake, chocolate, pie, cookie, donut |
unit | Box, tin, piece, item... |