Difference between database, schema, model and document?

Hi all,

I am trying to understand the meaning of database, schema, model and document.

Database and document seem easy: in excel the database would be a table and document would be a row in the table

But model and schema definitions I find online are too complex for me to understand

Does anyone have analogies/examples that connect these 4 words so that they are easy to understand? Making references to excel would be useful for me

Thanks for your time

Jaime

solution: https://replit.com/@jaimeggb/boilerplate-project-urlshortener

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/92.0.4515.107 Safari/537.36

Challenge: URL Shortener Microservice

Link to the challenge:

Hello there,

In Excel, I suppose a schema would be the button you use to format your cells into currency/accounting, number, or date.

A model is a bit more difficult to link, from what I know of Excel. So, I am going to try just explain them both as is:

Schema

  • Defines the data structure - how does the data look, and what is it made of
  • Helps prevent you from assigning an incorrect property/value to your document

Model

  • An object/class defined using a schema which enforces documents created using it to use the defined schema

I tend to think of it like: database > document > model > schema

  • Schemas define models
  • Models construct documents
  • Documents go in databases
  • Databases just are - collections (another common term) of Documents

Hope this helps

1 Like

So there are two main different categories of modern database, and both can sort of can be related to spreadsheets.

SQL vs NoSQL

An sql database correlates fairly well with a spreadsheet, in fact I’ve used a Google Sheet as a no-frills sql setup. NoSQL databases, like Mongo or firebase, do correlate, but it takes a but more imagination as NoSQL is quite a bit more flexible in its definitions.

  • the spreadsheet file equates to the database, the complete dataset container.
  • a given sheet in that spreadsheet represents a table in that spreadsheet, or a collection in a NoSQL database, collecting all the things representing one set of data (for example, a sheet named employees might represent a table of the same name).
  • the data types for each column in a sheet (this column might be text, the next might be an id, represented by a unique integer): this might represent a schema, and in the world of SQL this would be defined when the table is created.
  • a document in NoSQL does equate to a record or row in an sql database, or a rowin a particular sheet within excel, representing one member of a given data set.
  • and finally, a model. Regardless of where our data has been stored, when we actually use that data, pull it out and manipulate it or manipulate a display based on it, that record becomes a “live model”. The record in storage represents the data, but the model represents that thing in an interactable state. Am example of that might be payroll - our employee hours might simply be records in a sheet, but when we model that data, it can be meaningful to the payroll processing folks.
2 Likes

Hi @snowmonkey

Thanks for your extensive reply

I grasp what a schema is now, but I still don’t quite understand the difference between a model and a document.

Could you please give an example?

Thanks for your time

Jaime

This is a vast simplification but “model” typically refers to the representation of data in your program. That italicized part being the key.

“Document” refers to data outside of your program, usually for NoSQL databases.

1 Like

Sure, i can try. The document is the saved snapshot of the data, a “moment-in-time slice” of our thing, whilethe model represents the exact same data in actual application.

Again, suppose we have a collection of employees. A single employee record (or document) represents all the data points for that employee. Id, name, pay rate, times in/out, earned personal time, start date…everything about that employee is represented in her days document.

But the data itself means nothing until we “model” that data. Times in/out are meaningless in the document, but when we pull that into a model in our app, we can then manipulate the model to transform those times to hours worked, overtime worked, personal time accrued, weekly pay…

The document represents a static version of the thing in storage. The model represents that same data in dynamic use in our application.

It is a simplification, but for this conversation it’s entirely accurate.

And yes, i should have clarified: a document is that data in storage in a NoSQL setting.

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.