22MongoDB Atlas in Python
This chapter's example uses Python to build a NoSQL document database in the cloud. It uses the MongoDB Atlas database to save and query the following data about assignments for East Los Angeles Space Academy graduates, as shown in Table 22.1.
TABLE 22.1: Graduate assignments
FIRSTNAME | LASTNAME | POSITION | RANK | SHIP |
---|---|---|---|---|
Joshua | Ash | Fuse Tender | 6th Class | Frieda's Glory |
Sally | Barker | Pilot | Scrat | |
Sally | Barker | Arms Master | Scrat | |
Bil | Cilantro | Cook's Mate | Scrat | |
Al | Farnsworth | Diplomat | Hall Monitor | Frieda's Glory |
Al | Farnsworth | Interpreter | Frieda's Glory | |
Major | Major | Cook's Mate | Major | Athena Ascendant |
Bud | Pickover | Captain | Captain | Athena Ascendant |
The next few sections talk a bit about this data, the way document databases store information, and the MongoDB Atlas database that we'll use for this example. The rest of the chapter describes the example program.
NOT NORMAL BUT NOT ABNORMAL
If you remember the relational database normalization rules, then you know that the data in the preceding table is not normalized because some non-key fields do not depend on all the key fields. Here, the key fields are FirstName, LastName, and Position, because we need all three to identify a record. However, the fields Rank and Ship depend on FirstName and LastName but not on Position.
You can also see the problem by looking for anomalies. For example, if you change one of Sally Barker's Ship values, then her ship assignments will be inconsistent (an ...
Get Beginning Database Design Solutions, 2nd Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.