quinta-feira, 2 de fevereiro de 2023

[Mongo DB] Introduction to the Document Model

Hello all

One more step on Mongo DB University.

Today, I'm learning about MongoDB and the Document Model.


The main points of this module are: 

Overall, we can say that Mongo DB:
    - It's a General-Purpose Document Database.
    - By default, Mongo DB supports a flexible schema model and a polymorphic data. 
    - This allows us to store documents with different structures in the same collection.

The main advantages to use Mongo DB: 
    1) Documents offer a flexible and developer-friendly way to work with data.
    2) Easier and faster to plan how application data will correspond to data store in the database.
    3) Modal data of any shape or structure.
    4) Documents can model everything:
            Key-values pairs
    Text
    Geospatial indexes
    Time series
    Graph data
    and more
    5) Use one format for any application.
    6) Easy connect - Provide drivers in all major programming languages.
Basically, you can use Mongo DB in any application:
    E-commerce
    Content management
    IoT and time series data
    Trading and payments
    Gaming
    Mobile Apps
    Real-time analytics and AI
Your main features are:
    Scalability
    Resilience
    Speed of development
    High levels of data privacy
    Security
And finally, we have 3 Key term:
    Document - The basic unit of data on Mongo DB.
    
    Collection - A group of those documents. Documents in a collection are tipically similar they don't have the exact same structure, because Mongo DB has a flexible schema model.

    Database - A container for our collections. 

The Document model.

We can say many things about The Document Model, but this is the summary:
    - On Mongo DB, data is organized into documents, collections, and databases.
    - Mongo DB stores data in structures known as documents
    - Mongo DB structures data in documents, which are similar to JSON Objects
    - Documents are stored in BSON, which supports a large range of data types, including all JSON data types, dates, numbers, and ObjectIds.
    - Mongo DB displayed the data documents in JSON format, but they're stored in the database in a format called BSON (Binary JSON).
    - BSON is an extension of JSON and providing additional features 
    - BSON add support for additional data types unavailable in Standard JSON 
    - Every document requires an "_id" field, which acts as a primary key. 
    - The "_id" is a required field in every MongoDB document, but it's not a data type. If an inserted document does not include an "_id" field, MongoDB will automatically create the "_id" field and populate it with a value of type ObjectId.
    - Documents can contain different fields and fields may contains different data types.
    - If you want to have more control over the structure and content, we can add optional schema validation rules to set constraints on the structure of documents. 
Some Datatypes that you have on Mongo DB:
    All the JSON datatypes
        String
Object
Array
Boolean
Null
Dates
Numbers
ObjectIDs - It's a special data type used in Mongo DB to create unique identified.
    If you want moder information, click here.


Finally, an example to the syntax for a MongoDB document:

Syntax:
{
"key": value,
"key": value,
"key": value
}
Example:
    db.createCollection("blog") 
    
     "codigo": 2, 
     "trilogy": "Harry Potter", 
     "sequence": "Harry Potter and the Chamber of Secrets", 
     "year": "2002",
     "points": ["The first movie of trilogy", "I watched the movie at the cinema"]
    }

So that's it for today, folks.

I hope this helps you!

Regards
Mario

Postagem em destaque

[ORACLE] Cleanup Repository Area - Oracle Database Appliance (ODA)

Hello everyone. How are you doing? Today, I'll share with you a simple tip about ODA. When I need to clean the repository area, I use th...