-
Notifications
You must be signed in to change notification settings - Fork 0
/
delete.js
49 lines (48 loc) · 1.19 KB
/
delete.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
var mongo = require('mongodb')
var delData = function (db, data, callback) {
//连接到表
var collection = db.collection('news');
// console.log(data)
var o_id = new mongo.ObjectID(data.id);
var whereStr = {
"_id": o_id
};
//find data width id
collection.deleteOne(whereStr, function (err, result) {
if (err) {
console.log('Error:' + err);
return;
}
callback(result);
});
}
module.exports = function (MongoClient, DB_CONN_STR, mongo) {
return function (req, res, next) {
if (!req.session.user) {
res.statusCode = 404
var info = encodeURI('登陆超时')
res.header('info', info)
return res.send('')
}
var data = {}
if (req.body) {
data = req.body
} else if (req.query.id) {
data.id = req.query
} else {
// res.statusCode(400)
return res.send(400)
}
// console.log(id)
MongoClient.connect(DB_CONN_STR, function (err, db) {
// console.log("连接成功!");
delData(db, data, function (result) {
// console.log(result)
var info = encodeURI('操作成功')
res.header('info', info)
res.send(result);
db.close();
});
});
}
}