diff --git a/app.js b/app.js index cf87a13..aeb897e 100644 --- a/app.js +++ b/app.js @@ -1,7 +1,7 @@ const Koa = require("koa"); const requter = require("./bin/router.js"); jwt = require('jsonwebtoken'); -dbs = require("./bin/mongodb.js")('mongodb://localhost:27017/',"myblog") +dbs = require("./bin/mongodb.js")('mongodb://localhost:27017/myblog',"myblog") // console.log(requter) // import requter from "./bin/router" const app = new Koa(); diff --git a/bin/mongodb.js b/bin/mongodb.js index cfa09f4..b559fc1 100644 --- a/bin/mongodb.js +++ b/bin/mongodb.js @@ -1,8 +1,10 @@ var MongoClient = require('mongodb').MongoClient; var dburl; let add = (set,data,url = dburl) =>{ + // console.log(url) + return new Promise((resolve, reject) => { - MongoClient.connect(url.url, { useNewUrlParser: true }, function(err, db) { + MongoClient.connect(url.url, { useUnifiedTopology: true, useNewUrlParser: true}, function(err, db) { if (err) throw err; var dbo = db.db(url.dbname); // var myobj = { name: "菜鸟教程", url: "www.runoob" }; @@ -22,7 +24,7 @@ let add = (set,data,url = dburl) =>{ } let adds = (set,data,url = dburl) =>{ return new Promise((resolve, reject) => { - MongoClient.connect(url.url, { useNewUrlParser: true }, function(err, db) { + MongoClient.connect(url.url, { useUnifiedTopology: true, useNewUrlParser: true}, function(err, db) { if (err) throw err; var dbo = db.db(url.dbname); // var myobj = { name: "菜鸟教程", url: "www.runoob" }; @@ -42,7 +44,7 @@ let adds = (set,data,url = dburl) =>{ } let remove = (set,where,url = dburl) =>{ return new Promise((resolve, reject) => { - MongoClient.connect(url.url, { useNewUrlParser: true }, function(err, db) { + MongoClient.connect(url.url, { useUnifiedTopology: true, useNewUrlParser: true}, function(err, db) { if (err) throw err; var dbo = db.db(url.dbname); // var myobj = { name: "菜鸟教程", url: "www.runoob" }; @@ -65,7 +67,7 @@ let removes = (set,where,url = dburl) =>{ if(where == "" ||Object.keys(where).length == 0){ reject({code:1}) } - MongoClient.connect(url.url, { useNewUrlParser: true }, function(err, db) { + MongoClient.connect(url.url, { useUnifiedTopology: true, useNewUrlParser: true}, function(err, db) { if (err) throw err; var dbo = db.db(url.dbname); // var myobj = { name: "菜鸟教程", url: "www.runoob" }; @@ -84,9 +86,11 @@ let removes = (set,where,url = dburl) =>{ }) } let find = (set,where = {},page = 0,num = 0,url = dburl) =>{ + // console.log(url) + return new Promise((resolve, reject) => { if(num == 0){ - MongoClient.connect(url.url, { useNewUrlParser: true }, function(err, db) { + MongoClient.connect(url.url, { useUnifiedTopology: true, useNewUrlParser: true}, function(err, db) { if (err) throw err; var dbo = db.db(url.dbname); // var myobj = { name: "菜鸟教程", url: "www.runoob" }; @@ -103,7 +107,7 @@ let find = (set,where = {},page = 0,num = 0,url = dburl) =>{ }); }else{ - MongoClient.connect(url.url, { useNewUrlParser: true }, function(err, db) { + MongoClient.connect(url.url, { useUnifiedTopology: true, useNewUrlParser: true}, function(err, db) { if (err) throw err; var dbo = db.db(url.dbname); // var myobj = { name: "菜鸟教程", url: "www.runoob" }; @@ -125,7 +129,7 @@ let find = (set,where = {},page = 0,num = 0,url = dburl) =>{ } let update = (set,where = {},data,url = dburl) =>{ return new Promise((resolve, reject) => { - MongoClient.connect(url.url, { useNewUrlParser: true }, function(err, db) { + MongoClient.connect(url.url, { useUnifiedTopology: true, useNewUrlParser: true}, function(err, db) { if (err) throw err; var dbo = db.db(url.dbname); // var myobj = { name: "菜鸟教程", url: "www.runoob" }; @@ -146,7 +150,7 @@ let update = (set,where = {},data,url = dburl) =>{ } let updates = (set,where = {},data,url = dburl) =>{ return new Promise((resolve, reject) => { - MongoClient.connect(url.url, { useNewUrlParser: true }, function(err, db) { + MongoClient.connect(url.url, { useUnifiedTopology: true, useNewUrlParser: true}, function(err, db) { if (err) throw err; var dbo = db.db(url.dbname); // var myobj = { name: "菜鸟教程", url: "www.runoob" }; diff --git a/controllers/login.js b/controllers/login.js index 2461120..ee9cddb 100644 --- a/controllers/login.js +++ b/controllers/login.js @@ -1,37 +1,30 @@ -var login = async (ctx, next) => { - // var name = ctx.params.name; - // ctx.response.body = `