diff --git a/lib/mongoose-datatables.js b/lib/mongoose-datatables.js index 59a7d4f..350e7d8 100644 --- a/lib/mongoose-datatables.js +++ b/lib/mongoose-datatables.js @@ -77,9 +77,14 @@ function dataTablesPlugin (schema, options) { )){ return reject(new Error('Invalid formatter')) } + + var countDocuments = thisSchema.count(find) + if (thisSchema.countDocuments) { + countDocuments = thisSchema.countDocuments(find) + } Promise - .all([query.exec(), thisSchema.count(find)]) + .all([query.exec(), countDocuments]) .then(function (results) { var response = {} response[totalKey] = results[1]