-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmula.js
53 lines (35 loc) · 1003 Bytes
/
mula.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
const mongoose = require('mongoose');
const Schema = mongoose.Schema;
const MONGO_USERNAME = 'two';
const MONGO_PASSWORD = 'password';
const MONGO_HOSTNAME = '127.0.0.1';
const MONGO_PORT = '27017';
const MONGO_DB = 'blog';
const url = `mongodb://${MONGO_USERNAME}:${MONGO_PASSWORD}@${MONGO_HOSTNAME}:${MONGO_PORT}/${MONGO_DB}?authSource=blog`;
const conn = mongoose.createConnection(url, { useNewUrlParser: true });
const userSchema = new Schema({
name: String,
email: String,
password: String,
created_at: Date,
updated_at: Date
})
const postSchema = new Schema({
title: String,
author: String,
body: String,
comments: [{ body: String, date: Date }],
date: { type: Date, default: Date.now },
hidden: Boolean,
meta: {
votes: Number,
favs: Number
}
});
const PostModel = conn.model("Posts", postSchema);
const UserModel = conn.model("Users", userSchema);
module.exports = {
PostModel,
UserModel,
conn
}