-
Notifications
You must be signed in to change notification settings - Fork 0
/
db.js
80 lines (72 loc) · 1.35 KB
/
db.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
const db = require('mongoose');
db.Promise = global.Promise;
db.connect('mongodb://localhost:27017/MyEmail', {
useMongoClient: true,
promiseLibrary: global.Promise
});
db.connection.on('open', function () {
console.log('数据库连接成功~');
})
db.connection.on('error', function (err) {
console.log('数据库连接失败!' + err);
})
// 用户表
var User = db.model('user', {
name: String,//姓名
age: Number,//年龄
post_num: {//发帖数
type: Number,
default: 0
},
reply_num: {//回帖数
type: Number,
default: 0
}
})
// 发帖表
var Post = db.model('post', {
poster: {//发帖人
type: db.Schema.Types.ObjectId,
ref: 'user'
},
// poster: String,
title: String,//标题
content: String,//内容
reply_num: {//回帖数
type: Number,
default: 0
}
})
// 回帖表
var Reply = db.model('reply', {
post: {//发帖表
type: db.Schema.Types.ObjectId,
ref: 'post'
},
replier: {//回帖人
type: db.Schema.Types.ObjectId,
ref: 'user'
},
// post: String,
// replier: String,
content: String//内容
})
module.exports = { User, Post, Reply };
/**用户表
* 姓名
* 年龄
*/
/**发帖表
* 标题
* 内容
* 发件人---下拉框 用户表
* 评论
*
*/
/**回帖表
* 发帖id ---下拉框 发帖表
* 发帖人 ---下拉框 用户表
* 回帖人 ---下拉框 用户表
* 回帖标题
* 回帖内容
*/