var Ctrler = function(model) {
    this.model = (model) ? model : null;
}

// create model instance
Ctrler.prototype.create = function(baby, cb) {
    var baby = new this.model(baby);
    baby.save(function(err) {
        cb(err, baby);
    });
}

// remove by ObjectID
Ctrler.prototype.remove = function(id, cb) {
    this.model.findByIdAndRemove(id, function(err) {
        cb(err, id);
    });
}

// update by ObjectID
Ctrler.prototype.update = function(id, baby, cb) {
    this.model.findByIdAndUpdate(id, baby, function(err, result) {
        cb(err, result);
    });
}

// read single data by ObjectID
Ctrler.prototype.read = function(id, cb) {
    if (id && id.match(/^[0-9a-fA-F]{24}$/)) {
        this.model.findById(id).exec(function(err, body) {
            cb(err, body);
        });
    }
}

// list all collection
Ctrler.prototype.list = function(cb) {
    this.model.find({}).exec(function(err, body) {
        cb(err, body);
    });
}

// list by page
Ctrler.prototype.page = function(page, limit, params, cb) {
    var self = this,
        from = (page && page > 1) ? ((page - 1) * limit) : 0;
    self.model.count(params).exec(function(err, count) {
        if (!err) {
            self.model.find(params).skip(from).limit(limit).exec(function(err, results) {
                cb(err, results, {
                    limit: limit,
                    current: page ? page : 1,
                    max: Math.round(count / limit)
                });
            });
        } else {
            cb(err);
        }
    });
}

// advanced find
Ctrler.prototype.find = function(params, cb) {
    this.model.find(params).exec(function(err, body) {
        cb(err, body);
    });
}

// advanced findOne
Ctrler.prototype.findOne = function(params, cb) {
    this.model.findOne(params).exec(function(err, body) {
        cb(err, body);
    });
}

// advanced query:
// var demo = user.query('findOne',{name: 'demo'});
// demo.select('sth'); demo.exec(function(err,result){});
Ctrler.prototype.query = function(type, params) {
    return this.model[type](params);
}

module.exports = Ctrler;
@@ -72,33 +72,8 @@
 %0A%7D%0A%0A
-// create model instance%0A
 Ctrl
@@ -106,25 +106,31 @@
 tion(baby, c
-b
+allback
 ) %7B%0A    var 
@@ -193,25 +193,31 @@
  %7B%0A        c
-b
+allback
 (err, baby);
@@ -232,30 +232,8 @@
 %0A%7D%0A%0A
-// remove by ObjectID%0A
 Ctrl
@@ -247,20 +247,18 @@
 otype.re
-move
+ad
  = funct
@@ -266,25 +266,31 @@
 on(id, c
-b
+allback
 ) %7B%0A    
 this.mod
@@ -285,83 +285,104 @@
     
-this.model.findByIdAndRemove(id, function(err) %7B%0A        cb(err, id
+if (id && id.match(/%5E%5B0-9a-fA-F%5D%7B24%7D$/)) %7B%0A        this.model.findById(id).exec(callback
 );%0A    %7D
 );%0A%7D
@@ -381,36 +381,12 @@
    %7D
-);
 %0A%7D%0A%0A
-// update by ObjectID%0A
 Ctrl
@@ -427,17 +427,23 @@
  baby, c
-b
+allback
 ) %7B%0A    
@@ -485,99 +485,21 @@
 by, 
-function(err, result) %7B%0A        cb(err, result);%0A    %7D);%0A%7D%0A%0A// read single data by ObjectID
+callback);%0A%7D%0A
 %0ACtr
@@ -506,34 +506,36 @@
 ler.prototype.re
-ad
+move
  = function(id, 
@@ -539,329 +539,552 @@
 d, c
-b) %7B%0A    if (id && id.match(/%5E%5B0-9a-fA-F%5D%7B24%7D$/)) %7B%0A        this.model.findById(id).exec(function(err, body) %7B%0A            cb(err, body);%0A        %7D);%0A    %7D%0A%7D%0A%0A// list all collection%0ACtrler.prototype.list = function(cb) %7B%0A    this.model.find(%7B%7D).exec(function(err, body) %7B%0A        cb(err, body);%0A    %7D);%0A%7D%0A%0A// list by page
+allback) %7B%0A    this.model.findByIdAndRemove(id, callback);%0A%7D%0A%0ACtrler.prototype.count = function(params, callback) %7B%0A    var cb = (!callback && typeof(params) === 'function') ? params : callback,%0A        query = (params && typeof(params) === 'object') ? params : %7B%7D;%0A    this.model.count(query, cb);%0A%7D%0A%0ACtrler.prototype.list = function(params, callback) %7B%0A    var cb = (!callback && typeof(params) === 'function') ? params : callback,%0A        query = (params && typeof(params) === 'object') ? params : %7B%7D;%0A    this.model.find(query).exec(cb);%0A%7D%0A
 %0ACtr
@@ -1127,33 +1127,39 @@
 limit, params, c
-b
+allback
 ) %7B%0A    var self
@@ -1409,25 +1409,31 @@
            c
-b
+allback
 (err, result
@@ -1630,25 +1630,31 @@
            c
-b
+allback
 (err);%0A     
@@ -1720,33 +1720,39 @@
 nction(params, c
-b
+allback
 ) %7B%0A    this.mod
@@ -1776,58 +1776,16 @@
 xec(
-function(err, body) %7B%0A        cb(err, body);%0A    %7D
+callback
 );%0A%7D
@@ -1851,17 +1851,23 @@
 arams, c
-b
+allback
 ) %7B%0A    
@@ -1902,58 +1902,16 @@
 xec(
-function(err, body) %7B%0A        cb(err, body);%0A    %7D
+callback
 );%0A%7D

update base ctrler