-
Notifications
You must be signed in to change notification settings - Fork 9
/
model.js
56 lines (52 loc) · 1.05 KB
/
model.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
const mongoose = require('mongoose');
const UserSchema = new mongoose.Schema({
group_id: {
type: String,
required: true,
},
member: {
type: String,
required: true
},
content: {
type: String,
default: '',
},
date: {
type: Date,
default: Date.now,
},
finished:{
type: Boolean,
default: false,
}
});
// collection name 'report' in mlab
const User = mongoose.model('report', UserSchema);
module.exports = User;
/* CRUD
// create
function create_(data_obj){
var newUser = new User(data_obj);
newUser.save().catch(err=>console.log(err));
// User.insertMany([{},{},{}]).exec();
}
// read
function read_(data_obj){
User.findOne(data_obj).then(user=>{return user})
}
// update
function update_(find_obj,updata_obj){
User.update(find_obj,updata_obj)
.exec()
.then()
.catch(err=>console.log(err));
}
// delete
function delete_(data_obj){
User.deleteOne(data_obj)
.exec()
.then()
.catch(err=>console.log(err));
}
*/