var mongoose = require('mongoose'); var Schema = mongoose.Schema; /*定义数据模式*/ var ClassSchema = new mongoose.Schema({ name: String, meta: { createAt: { type: Date, default: Date.now() }, updateAt: { type: Date, default: Date.now() } } /*更新时间的*/ }); module.exports = ClassSchema;
・ 生成Model(model目录下)
1. student Model(student.js)
var mongoose = require('mongoose'); var StudentSchema = require('../schemas/student'); /*通过model编译模式为模型*/ var Student = mongoose.model('student', StudentSchema); /*导出Student模型 模块*/ module.exports = Student;
2. class Model(class.js)
var mongoose = require('mongoose'); var ClassSchema = require('../schemas/class'); /*通过model编译模式为模型*/ var Class = mongoose.model('class', ClassSchema); /*导出Class模型 模块*/ module.exports = Class;