javascript Mongoose Schema继承
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了javascript Mongoose Schema继承相关的知识,希望对你有一定的参考价值。
const mongoose = require('mongoose')
const { PersonSchema } = require('./person')
class ManSchema extends PersonSchema {
constructor(obj, options) {
super(obj, options)
this.add({ age: { type: String, required: true } })
}
}
const Man = new ManSchema({}, { timestamps: true }, { usePushEach: true })
module.exports = mongoose.model('Man', Man)
const mongoose = require('mongoose')
const { Schema } = mongoose
class PersonSchema extends Schema {
constructor(obj, options) {
super(obj, options)
this.add({ name: { type: String, required: true } })
}
}
const Person = new PersonSchema({}, { timestamps: true }, { usePushEach: true })
exports.PersonSchema = PersonSchema
exports.Person = mongoose.model('Person', Person)
以上是关于javascript Mongoose Schema继承的主要内容,如果未能解决你的问题,请参考以下文章
Mongoose 查询:填充来自 Post Schema 的前 2 条评论
javascript [mongoose connect]功能连接到mongoose #mongoose
mongoose 查询返回纯 javascript
在 javascript 中连接到 mongoose 数据库时出错
为啥 Mongoose 的 JavaScript 在同一行同时有返回和回调?
javascript 使用Mongoose过滤