通過(guò)student的classId關(guān)聯(lián)進(jìn)行查詢(xún)學(xué)生名稱(chēng),班級(jí)的數(shù)據(jù):SELECT student.name,student.age,class.name FROM student,class WHERE student.classId = class.id
var mongoose = require('mongoose'); var Schema = mongoose.Schema; /*定義數(shù)據(jù)模式*/ var ClassSchema = new mongoose.Schema({ name: String, meta: { createAt: { type: Date, default: Date.now() }, updateAt: { type: Date, default: Date.now() } } /*更新時(shí)間的*/ }); module.exports = ClassSchema;
・ 生成Model(model目錄下)
1. student Model(student.js)
var mongoose = require('mongoose'); var StudentSchema = require('../schemas/student'); /*通過(guò)model編譯模式為模型*/ var Student = mongoose.model('student', StudentSchema); /*導(dǎo)出Student模型 模塊*/ module.exports = Student;
2. class Model(class.js)
var mongoose = require('mongoose'); var ClassSchema = require('../schemas/class'); /*通過(guò)model編譯模式為模型*/ var Class = mongoose.model('class', ClassSchema); /*導(dǎo)出Class模型 模塊*/ module.exports = Class;