删除注释

This commit is contained in:
pplokijuhyg 2019-11-13 11:01:42 +08:00
parent 95537ddcbb
commit b12d5ca7e6

View File

@ -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});
});