Lompat ke konten Lompat ke sidebar Lompat ke footer

Draw a Tape Diagram to Model Each Comparison

NoSql, unlike SQL which has ER and course diagrams, has neither names nor constraints for data modeling diagram(s). The obvious reason is the relax rules of NoSql nearly relationships, which aim to go a developer started with minimum requirements.

Since data modeling diagram is the blueprint of any application we should always draw one. For tool I adopt diagrams.internet (previously draw.io), where you simply need to drag and drop symbols into the sheet and align them. Its "Entity Relation" section on the left bill of fare is most suitable for our modeling.

Example Problem Statement

Permit us take a problem statement and draw our data model diagram around it in steps:

In that location'due south a gift store full of souvenir items. Multiple cashiers perform duty at different times of day and sell these items to customers. Customers are unregistered in organisation but their name is inquired and put on receipt.

In other words, we need to build a basic gift inventory and checkout system in lite of above information. So, nosotros commencement by identifying obvious and unsaid entities.

The Entities

  • Item
  • Product - not mentioned simply required to distinguish betwixt say Hugo Dominate perfume (production) and 10 bottles of it (items)
  • Cashier
  • Transaction - a more than informative word than "sell" or "purchase"

And that'southward all we need. Customer is not required considering nosotros just need its proper name and has no other information. Receipt is unnecessary as all information to print on receipt is available in transaction.

Brand could be an entity of its own, if we want to store anything more than than its proper name. If it'southward just a proper noun, like 'Nike', nosotros can store it as an indexed holding of the Product, and group products by it for brand related queries.

Listing Down Possible Queries

During the modeling process, it'south ever helpful to programme ahead the read and write operations, to be able to keep them efficient and call back meaningful information from our data.

one. Reading Data

Requirements change with time, and NoSql is meant to adjust that, but you lot must put in some thought near the initial minimum you tin can specify at the start. In our case, it will be:

  • Rank the best performing brands and products within a given timeframe
  • Identify the items that need restocking
  • Transaction breakdown by any period of time: hourly, daily, weekly, monthly, yearly (we might need to draw and compare charts for insights)
  • Listing down cashiers based on seniority
  • A customer has lost the receipt, but they know what products they purchased and when. By querying the transactions, impress them a duplicate receipt
  • Get all products that are less than $50 (a customer may inquire the cashier)

Obviously, this is not an exhaustive list, just we become the basic idea.

2. Writing Information

For this part, we should mostly be concerned with how references are stored given the amount of expanding data and frequency of updates. In some other detailed post, I've explained ways to model NoSql 1 to one, ane to many, and many to many relationships along with their pros and cons. Briefly:

Ever Expanding Information

If number of documents are ever increasing, never put them or their references in some other document. For example, number of items will go on on increasing, so nosotros can't embed or add their ids as reference within product, as somewhen it will become also big and run out of the maximum allocated space per document, non to mention deadening to fetch. Instead we should keep the product reference in each detail.

Frequent Additions And Updates

If some certificate(south) crave a lot of adds, updates, or deletes, don't embed them or put their reference at a single place, because it could result in:

  • Slowing down the database operations
  • Possible Inconsistent information, if operations were performed non atomically (i.e. a document was fetched, modified on customer side, and so updated. Between your fetch and update, somebody else might have updated the document, and now yous take the outdated information that your update call will persist).

For example: Y'all embed comments and like of users inside a post. The post gets thousands of comments and likes in a short fourth dimension. Many would update their comments likewise. This means that the post will need to be updated thousands of times in a brusque interval. Merely if comments and likes had their own collections, every comment would take been added and updated separately and much efficiently.


Now let's move to the breakdown of all entities with diagrams, their relation with others, and example documents. Due to its familiarity I'thou using MongoDB'southward collections as entities and documents as examples.

Product

                              {                id:                1,                proper noun:                "Dark Blue Cologne"                ,                brand:                "Hugo Dominate"                ,                toll:                22.46                }                          

Cashier

                              {                id:                1,                proper noun:                "John Smith"                ,                cellNum:                "4565456789"                ,                address:                "Broadway Street house no. 12, Brooklyn, New York, Usa"                ,                ssn:                "011-72-XXXX"                .                .                .                }                          

Product Has Many Items

                              //products                                                {                id                :                1                ,                name                :                "Night Blue Cologne"                ,                brand                :                "Hugo Boss"                ,                cost                :                22.46                }                //items                                                {                id                :                1                ,                productId                :                one                ,                barcode                :                "0705632441947"                }                {                id                :                2                ,                productId                :                one                ,                barcode                :                "0705632441948"                }                {                id                :                3                ,                productId                :                one                ,                barcode                :                "0705632441949"                }                          

Note that in low-cal of the above reasoning, we haven't put embedded items or their references in an array inside the production document. Nosotros continue productId as a reference in items instead.

Transaction

Transaction is a required associative collection to solve following many to many problem:

  • A cashier can sell unlimited number of product items (Cashier John sells fifteen sets of Hugo'south Dark Blueish Cologne)
  • A product detail can exist sold by many cashiers (Hugo'southward Dark Blueish Cologne is sold by cahiers John, Tony, Malinda, George and 2 others)

salePrice is necessary to know at what cost the production item was sold (in instance of discount information technology'll be less)

It might exist tempting to model transaction on existent earth scenario where a customer buys multiple items in one go, which are shown in receipt as such. However, transaction should represent just one auction. For buying of multiple items, say 10 at a time, 10 transaction documents should be created. You can create another collection to group multiple transactions or just place some unique identifier field (ex: transactionId) in all of transactions fabricated collectively at one fourth dimension.

Transaction Belongs To Product, Cashier And Item

This relationship can besides be described as: Product has many Transactions, Cashier has many Transactions, Item has many Transactions.

"Product has many Transactions" is completely optional and depends on requirements. For case, when you demand to generate yearly reports of sale and therefore demand to know products in aggregated data, it'southward easier to accept product reference in transaction document than getting it through item (which will either require bring together if available in the database, or multiple queries).

                              //products                                                {                id                :                ane                ,                proper name                :                "Dark Blue Cologne"                ,                brand                :                "Hugo Dominate"                ,                price                :                22.46                }                //items                                                {                id                :                1                ,                productId                :                1                ,                barcode                :                "0705632441947"                }                {                id                :                2                ,                productId                :                1                ,                barcode                :                "0705632441948"                }                {                id                :                three                ,                productId                :                1                ,                barcode                :                "0705632441949"                }                // cashiers                                                {                id                :                1                ,                name                :                "John Smith"                ,                cellNum                :                "4565456789"                ,                address                :                "Broadway Street house no. 12, Brooklyn, New York, US"                ,                ssn                :                "011-72-XXXX"                .                .                .                }                {                id                :                2                ,                name                :                "Malinda Johnson"                ,                cellNum                :                "4565456689"                ,                address                :                "Harold Street firm no. 133, Brooklyn, New York, US"                ,                ssn                :                "011-73-XXXX"                .                .                .                }                //transactions                                                {                id                :                1                ,                productId                :                1                ,                itemId                :                1                ,                customerName                :                "Daniel Witz"                ,                cashierId                :                i                ,                salePrice                :                22                //salePrice to provide discount option                                                }                {                id                :                1                ,                productId                :                1                ,                itemId                :                two                ,                customerName                :                "Glenn McDowell"                ,                cashierId                :                ane                ,                salePrice                :                22                }                {                id                :                1                ,                productId                :                1                ,                itemId                :                3                ,                customerName                :                "Robert Williams"                ,                cashierId                :                2                ,                salePrice                :                22                }                          

Finalizing The Diagram

We've finished our first blueprint iteration and cartoon! It efficiently takes care of the read and correct considerations we listed down earlier. This basic diagram tin can be improved as the application development proceeds and the requirements are modified.

As noted earlier, NoSql information modeling lacks conventional names and design principles similar to that of SQL. For this, it's always ameliorate to include the symbols used in the diagram itself for ease of reading for everyone. Let's add entity and one-to-many symbols, the just two used.

Example Of Olympic Games

Let'southward take another quick example and repeat the above steps to reach a final diagram.

Problem Statement

Create an awarding for Olympic Games

Entities

  • OlympicEvent - to store data for Olympic event, such equally the country it'southward taking place in, yr etc.
  • Stadium - where the games are played
  • Athlete
  • Official - the match officials
  • Competition - to store the details of actual contest
  • Game - which is played past athletes and of which competition is conducted

Possible Queries

  • Find all archery participants from London Olympics 2012
  • Notice countries which qualified for Table Tennis in Tokyo Olympics 2020
  • Become country name with highest number of games in Beijing Olympics 2008
  • For the final 4 Olympic games, get all the gold and silvery medalists medalists

Information Model Diagram

Relationships Explained

  1. An OlympicEvent conducts many Games (One To Many)
  2. Many Games are played in a Stadium (One To Many)
  3. A Game is played by many Athletes and an Athlete can play multiple Games (Many To Many)
  4. Many Athletes and Officials participate in multiple Competitions; And a Competition has many Athletes and Officials (Both Many To Many)
  5. A Competition can only be of i Game, but a Game is played by numerous Competition (One To Many)

Note that for many to many relationship between Athlete/Competition and Official/Competition, we simply keep an array of references in Competition document, instead of keeping associate collections in between, because a competition won't have unlimited number of athletes or officials participating, nor will it be updated that oftentimes.

See also

  • Nosql Many-to-Many Human relationship Examples; Jump And Unbound Cases
  • NoSql 1-to-Many Relation Examples; Bound And Unbound Cases
  • NoSql Instance Of Split up Collections In One-to-Ane Human relationship; Case Of Specialization And Generalization
  • NoSql Data Modeling: i to 1, i to Many, Many to Many

rickettsdethe1948.blogspot.com

Source: https://www.techighness.com/post/how-to-draw-no-sql-data-model-diagram/

Posting Komentar untuk "Draw a Tape Diagram to Model Each Comparison"