【发布时间】:2019-03-24 18:36:48
【问题描述】:
const mongoose = require('mongoose');
const Schema = mongoose.Schema;
const modelSchema = new Schema({
a: String,
b: Date
});
我知道第一行返回的是一只猫鼬。但是 mongoose.Schema 在这段代码中究竟返回了什么?为什么要写第三行“const modelSchema = new Schema(...)”?
【问题讨论】:
-
第二行的 Schema 是 Mongoose 中的“类”或对象,从中派生出任何新的 Schema 实例。您必须先导入 Schema 对象,然后为了使用它,您需要为每个需要架构的模型实例化一个新实例。
标签: javascript mongoose