设为首页 加入收藏

TOP

Nodejs 做后台完整业务案例(五)
2017-12-29 06:07:19 】 浏览:547
Tags:Nodejs 后台 完整 业务 案例
nbsp;           }
            if (doc != null) {
                result.push(doc);  //放入结果数组
            } else {
                //遍历结束,没有更多的文档了
                callback(null, result);
                db.close(); //关闭数据库
            }
        });
    });
}


//删除
exports.deleteMany = function (collectionName, json, callback) {
    _connectDB(function (err, db) {
        //删除
        db.collection(collectionName).deleteMany(
            json,
            function (err, results) {
                callback(err, results);
                db.close(); //关闭数据库
            }
        );
    });
}
// findmany
exports.findmany = function(cname, con, filter, cb){
    _connectDB(function (err, db) {
        db.collection(cname).find(con, filter).toArray(function(err, docs){
            cb(err, docs);
            db.close();
        });
    });
};
// findone
exports.findone = function(cname, con, op, cb){
    _connectDB(function (err, db) {
        db.collection(cname).findOne(con,{fields:op}, function(err, doc){
            cb(err, doc);
            db.close();
        });
    });
};
//修改
exports.updateMany = function (collectionName, json1, json2, callback) {
    _connectDB(function (err, db) {
        db.collection(collectionName).updateMany(
            json1,
            json2,
            function (err, results) {
                callback(err, results);
                db.close();
        });
    })
};


exports.getAllCount = function (collectionName,callback) {
    _connectDB(function (err, db) {
        db.collection(collectionName).count({}).then(function(count) {
            callback(count);
            db.close();
        });
    })
}


exports.count = function(cname,cond,cb){
    _connectDB(function (err, db) {
        db.collection(cname).count(cond).then(function(count) {
            cb(count);
            db.close();
        });
    });
}


exports.one = function(cname, cond, cb){
    _connectDB(function (err, db) {
        db.collection(cname).count(cond).then(function(err, one) {
            cb(err, one);
            db.close();
   

首页 上一页 2 3 4 5 下一页 尾页 5/5/5
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
上一篇Python 迭代器 Iterator 下一篇使用Akka Actor和Java 8构建反应..

最新文章

热门文章

Hot 文章

Python

C 语言

C++基础

大数据基础

linux编程基础

C/C++面试题目