Saltar al contenido principal
Version: 1.x

The Todo Model

Let's create your first model. The CLI provides a useful command to generate a new file with an empty model.

foal generate model todo

FoalTS uses Mongoose, a complete Object-Document Mapper, to communicate with the MongoDB database.

Open the file todo.model.ts in the src/app/models directory and add a text field.

import { model, models, Schema } from 'mongoose';

const todoSchema = new Schema({
text: {
required: true,
type: String // String with a capital letter
}
});

export const Todo = models.Todo || model('Todo', todoSchema);