var mongodb = require("mongodb");
var db = require("../modules/db");
// 添加
module.exports.postAdd=function (req,res) {
var obj = req.body;
obj.age = +obj.age;
obj.time = new Date().getTime();
obj.snum = +obj.snum;
db.insertOne(res,obj, "case1115",function (err,result,db1) {
if (err) {
res.send({code:404,msg:"添加失败"})
} else {
res.send({ code: 200, msg: "添加失败" })
db1.close();
}
})
}
// 渲染
module.exports.getList = function (req, res) {
var obj = req.query;
console.log(obj);
// obj.find ? obj.find.$or[0].snum -= 0 : "";
db.find(res, obj,"case1115",function (err, result, db1) {
if (err) {
res.send({ code: 404, msg: "添加失败" })
} else {
res.send({ code: 200, msg: "添加失败",info:result })
db1.close();
}
})
}
// 删除
module.exports.getDel = function (req, res) {
var id = req.query.id;
var obj = {
_id:mongodb.ObjectId(id)
}
db.deleteOne(res, obj, "case1115", function (err, result, db1) {
if (err) {
res.send({ code: 404, msg: "添加失败" })
} else {
res.send({ code: 200, msg: "添加失败"})
db1.close();
}
})
}
// 删除
module.exports.getdelAll = function (req, res) {
db.drop(res, {}, "case1115", function (err, result, db1) {
if (err) {
res.send({ code: 404, msg: "添加失败" })
} else {
res.send({ code: 200, msg: "添加失败" })
db1.close();
}
})
}
MongoDB
最新推荐文章于 2024-09-03 16:41:45 发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)