-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdataBase.js
84 lines (75 loc) · 1.99 KB
/
dataBase.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
81
82
83
84
/*
* dataBase server
*/
const projects = require('./src/projectsConfig');
const images = require('./src/imagesConfig');
let mongoose = require('mongoose');
let db = mongoose.connection;
mongoose.connect("mongodb://localhost:27017/mydb");
db.on('error', () => console.error.bind(console, 'connection error:'));
db.on('connected', () => console.log('db connected'));
db.once('open', () => console.log('db opened'));
let workDraftSchema = mongoose.Schema({
name: String,
title: String,
createTime: Date,
uploadTime: { type: Date, default: Date.now()},
url: String,
description: String,
author: String,
size: Number,
detailPictures: []
});
workDraftSchema.methods.uploaded = (name) => {
console.log(name + 'stored into db');
};
let workDraftModel = mongoose.model('workDraft', workDraftSchema);
// projects
// let works = [];
// projects.forEach(projectConfig => {
// works.push(new workDraftModel(projectConfig));
// });
//
// works.forEach(work => {
// work.save((err) => {
// if(err) {
// return console.error(err);
// }
// work.uploaded(work.name);
// });
// });
//
// images
// let imageWorks = [];
// images.forEach(imageConfig => {
// imageWorks.push(new workDraftModel(imageConfig));
// });
// imageWorks.forEach(image => {
// image.save((err) => {
// if(err) {
// return console.error(err);
// }
// image.uploaded(image.name);
// });
// });
//
// workDraftModel.find({name: 'project'}, (err, works) => {
// if (err) {
// console.error(err);
// }
// console.log('work from db: ' + works)
// }).remove().exec();
//
// workDraftModel.find({name: 'image'}, (err, works) => {
// if (err) {
// console.error(err);
// }
// console.log('work from db: ' + works)
// }).remove().exec();
workDraftModel.find((err, works) => {
if (err) {
console.error(err);
}
console.log('work from db: ' + works)
});
module.exports = workDraftModel;