var MongoClient = require('mongodb').MongoClient;
var DB_CONN_STR = "mongodb://localhost:27017/datas"; //datas是数据库名字
app.post('/fenlei', function (req, res){
console.log(req.body)
var insertData = function(db,callback){
var collection = db.collection("site"); //site数据表名
var data=[req.body]
collection.insert(data,function(err,result){
if(err){
console.log("error"+err);
return;
}
callback(result)
})
}
MongoClient.connect(DB_CONN_STR,function(err,db){
console.log("连接成功");
insertData(db,function(result){
console.log(result);
db.close()
})
})