From b12d5ca7e658cb235d72ac6341b98753bd35fa46 Mon Sep 17 00:00:00 2001 From: pplokijuhyg <1162963624@qq.com> Date: Wed, 13 Nov 2019 11:01:42 +0800 Subject: [PATCH] =?UTF-8?q?=E5=88=A0=E9=99=A4=E6=B3=A8=E9=87=8A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bin/mongodb.js | 20 +------------------- 1 file changed, 1 insertion(+), 19 deletions(-) diff --git a/bin/mongodb.js b/bin/mongodb.js index b559fc1..d7e084b 100644 --- a/bin/mongodb.js +++ b/bin/mongodb.js @@ -7,11 +7,9 @@ let add = (set,data,url = dburl) =>{ 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" }; try { dbo.collection(set).insertOne(data, function(err, res) { if (err) throw err; - // console.log("文档插入成功"); db.close(); resolve({code:0}); }); @@ -27,11 +25,9 @@ let adds = (set,data,url = dburl) =>{ 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" }; try { dbo.collection(set).insertMany(data, function(err, res) { if (err) throw err; - // console.log("文档插入成功"); db.close(); resolve({code:0,num:res.insertedCount}); }); @@ -47,11 +43,9 @@ let remove = (set,where,url = dburl) =>{ 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" }; try { dbo.collection(set).deleteOne(where, function(err, obj) { if (err) throw err; - // console.log("文档插入成功"); db.close(); resolve({code:0}); }); @@ -70,11 +64,9 @@ let removes = (set,where,url = dburl) =>{ 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" }; try { dbo.collection(set).deleteMany(where, function(err, obj) { if (err) throw err; - // console.log("文档插入成功"); db.close(); resolve({code:0,num:obj.result.n}); }); @@ -86,18 +78,14 @@ 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, { useUnifiedTopology: true, useNewUrlParser: true}, function(err, db) { if (err) throw err; var dbo = db.db(url.dbname); - // var myobj = { name: "菜鸟教程", url: "www.runoob" }; try { - dbo.collection(set). find(where).toArray(function(err, result) { // 返回集合中所有数据 + dbo.collection(set). find(where).toArray(function(err, result) { if (err) throw err; - // console.log(result); resolve({code:0,data:result}); db.close(); }); @@ -110,11 +98,9 @@ let find = (set,where = {},page = 0,num = 0,url = dburl) =>{ 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" }; try { dbo.collection(set). find(where).skip(num * page).limit(num).toArray(function(err, result) { // 返回集合中所有数据 if (err) throw err; - // console.log(result); resolve({code:0,data:result}); db.close(); }); @@ -132,12 +118,10 @@ let update = (set,where = {},data,url = dburl) =>{ 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" }; data = {$set:data} try { dbo.collection(set).updateOne(where, data, function(err, res) { if (err) throw err; - // console.log(result); resolve({code:0}); db.close(); }); @@ -153,12 +137,10 @@ let updates = (set,where = {},data,url = dburl) =>{ 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" }; data = {$set:data} try { dbo.collection(set).updateMany(where, data, function(err, res) { if (err) throw err; - // console.log("文档插入成功"); db.close(); resolve({code:0,num:res.result.nModified}); }); -- 2.39.5