📄️ Philosophy
Models are objects that aim to manage a single document in a collection, it also provides multiple ways of creating, updating, deleting and fetching documents as utilities.
📄️ Create New Document
In the previous section, we've seen how to create a document by creating a new instance of the model then calling the save method, this is a way, let's recap it quickly.
📄️ Casting Data
As Mongodb nature, any document can literally have any data type. However, when it comes to the data that is being sent to the client, it is important to cast the data to the correct type. This is because the client will be expecting a certain type of data, but making sure the data is inserted in a proper type is more important.
📄️ Casting Custom Fields
Casting custom fields are another common use case for custom fields. For example, we need to generate a slug field from the title field. We can use the cast method to cast the title field to a slug field, because we don't need to add slug field when creating a new post from outside the model.
📄️ Default values
When creating new model, you can specify default values for fields. These values will be used when creating new records if the field is not specified.
📄️ Model Data
Introduction
📄️ Embedded documents
Introduction
📄️ Saving Models
Introduction
📄️ Destroying Models
There are two ways to destroy a model, one when we have an instance of the model and the other when we don't.
📄️ Fetching Documents
Introduction