NIUCLOUD是一款SaaS管理后台框架多应用插件+云编译。上千名开发者、服务商正在积极拥抱开发者生态。欢迎开发者们免费入驻。一起助力发展! 广告
[toc] ## pre 创建一个Schema时,我们能通过`new mongoose.Schema`的第二个参数——配置对象,来为我们的Schema添加配置 ``` const UserSchema = new mongoose.Schema(define, {timestamps: true}); ``` ## timestamps 自动添加时间戳 ``` const UserSchema = new mongoose.Schema(define, {timestamps: true}); ``` ## collection 如果你指定Schema的时候指定了`collection`的值,那么会使用这个值作为集合的名字 ,否则就是模型名转小写再转复数 -> User-user-users ``` const UserSchema = new mongoose.Schema(define, {collection:'user'}); ```