Modelling our data
We already mentioned before that Mongoose works with the concept of “schemas.”
Mongoose schemas play a similar role to TypeORM entities. However, unlike the latter, the former are not classes, but rather plain objects that inherit from the Schema
prototype defined (and exported) by Mongoose.
In any case, schemas need to be instantiated into “models” when you are ready to use them. We like to think about schemas as “blueprints” for objects, and about “models” as object factories.
Our first schema
With that said, let’s create our first entity, which we will name Entry
. We will use this entity to store entries (posts) for our blog. We will create a new file at src/entries/entry.entity.ts
; that way TypeORM will be able to find this entity file since earlier in our configuration we specified that entity files will follow the src/**/*.entity.ts
file naming convention.
Let’s create our first schema. We...