Skip to content

Defining and Accessing a Model

Alexey Gordeyev edited this page Apr 7, 2015 · 1 revision

Defining a Model

Models are defined through the Schema interface.

// define models
var Post = schema.define('Post', {
    title:     { type: schema.String,  limit: 255 },
    content:   { type: schema.Text },
    params:    { type: schema.JSON },
    date:      { type: schema.Date,    default: Date.now },
    published: { type: schema.Boolean, default: false, index: true }
});

// simplier way to describe model
var User = schema.define('User', {
    name:         String,
    bio:          schema.Text,
    approved:     Boolean,
    joinedAt:     Date,
    age:          Number
});

Accessing a Model

// models also accessible in schema:
schema.models.User;
schema.models.Post;