2024-08-27 10:10:05 +08:00

37 lines
1.1 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

const mongoose = require("mongoose");
// 定义对应的 Schema
const issueSchema = new mongoose.Schema(
{
id: String, // mongodb 自动生成的 id
issueTitle: String, // 问题标题
issueContent: String, // 问题描述
issuePic: String, // 问题图片
scanNumber: Number, // 问题浏览量
commentNumber: Number, // 评论数
issueStatus: Boolean, // 问题状态
issueDate: String, // 问题时间
userId: {
type: mongoose.Schema.Types.ObjectId,
ref: "userModel", // 关联的模型
}, // 用户 id
typeId: {
type: mongoose.Schema.Types.ObjectId,
ref: "typeModel", // 关联的模型
}, // 所属分类
},
{
versionKey: false,
}
);
// 通过 Schema 来创建相应的数据模型
// 创建数据模型的方法为 mongoose.model只传一个名字代表查找到对应名字的模型
// 如果传入 Schema代表创建模型 (1) 给模型取一个名字 2对应的 Schema 3对应的集合
mongoose.model("issueModel", issueSchema, "issues");
// 将此模型进行导出
module.exports = mongoose.model("issueModel");