Skip to content
Branch: master
Find file Copy path
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
30 lines (20 sloc) 770 Bytes

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 { Document, model, Model, models, Schema } from 'mongoose';

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

export interface ITodo extends Document {
  text: string; // string a lowercase letter

export const Todo: Model<ITodo> = models.Todo || model<ITodo>('Todo', todoSchema);
You can’t perform that action at this time.