-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
59 lines (50 loc) · 1.27 KB
/
index.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
var mongoose = require('mongoose'),
Schema = mongoose.Schema,
ObjectId = Schema.ObjectId,
dbname = 'tiger_blog',
url = 'mongodb://tiger:qwert!#$%@localhost:27017/'+dbname,
port = 27017,
db = mongoose.createConnection();
mongoose.connect(url, {auth:{authdb:'tiger_blog'}}, function (err) {
if (err) {
console.error('connect to %s error: ', dbname, err.message);
process.exit(1);
}
console.log('mongodb connect')
});
// model
var Schema = mongoose.Schema;
// 文章
var ArticleSchema = new Schema({
title: String,
content: String,
tags : [String],
date: { type: Date, default: Date.now },
comments: [{
content: String,
date: { type: Date, default: Date.now },
name : String
}]
});
// user
var UserSchema = new Schema({
name : String,
email : String,
password : String,
token : String,
icon : String,
date : { type:Date , default : Date.now }
})
// comments
var CommentSchema = new Schema({
name : String,
content : String,
date : { type:Date , default : Date.now },
article_id : { type : ObjectId },
user_id : { type : ObjectId }
})
module.exports = {
Article : mongoose.model('Artilce', ArticleSchema),
User : mongoose.model('Users',UserSchema),
Comment : mongoose.model('Comment',CommentSchema)
}