question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

DeprecationWarning: collection.count is deprecated

See original GitHub issue

I use Node v8.11.1 and these packages:

"mongoose": "^5.2.2",
"mongoose-paginate": "^5.0.3"

And this get this warning during execution of paginate():

(node:9893) DeprecationWarning: collection.count is deprecated, and will be removed in a future version. Use collection.countDocuments or collection.estimatedDocumentCount instead

Issue Analytics

  • State:open
  • Created 5 years ago
  • Reactions:18
  • Comments:12

github_iconTop GitHub Comments

14reactions
c-carrascocommented, Jul 16, 2018

Same problem. I have forked the project (from version-5.0.3) to fix the warning.

npm install git://github.com/zerok78/mongoose-paginate.git#version-5.0.4 -S

11reactions
pararellcommented, Jul 15, 2018

Same problem here and because I’m not sure if there will be any update here, I have created small service on base this library, used in schema on the same principle but return promise and using only page, sort and limit, maybe it will help -

function paginate(query, options) {
    query   = query || {};
    options = Object.assign({}, paginate.options, options);

    const sort  = options.sort;
    const limit = options.hasOwnProperty('limit') ? options.limit : 10;
    const page  = options.page || 1;
    const skip  = options.hasOwnProperty('page') ? ((page - 1) * limit) : 0;
    const docs = limit
     ? this.find(query).sort(sort).skip(skip).limit(limit).exec()
     : query.exec();
    const countDocuments = this.countDocuments(query).exec();

    return Promise.all([docs, countDocuments]).then(function(values) {
      return Promise.resolve({
        docs:  values[0],
        total: values[1],
        limit: limit,
        page: page,
        pages: Math.ceil(values[1] / limit) || 1
      })
    });
}

module.exports = function(schema) {
    schema.statics.paginate = paginate;
};

module.exports.paginate = paginate;
Read more comments on GitHub >

github_iconTop Results From Across the Web

mongodb-nodejs-driver, DeprecationWarning: collection.count ...
As you figured out, starting from MongoDB Node.JS driver v3.1 the count() method has been deprecated and will be replaced with : Collection....
Read more >
DeprecationWarning: collection.count is deprecated #6831
The underlying mongodb driver has deprecated the .count() method. You should use .estimatedDocumentCount() or .countDocuments() instead.
Read more >
count is deprecated. Use Collection.count_documents instead ...
py:2: DeprecationWarning: count is deprecated. Use Collection.count_documents instead. after executing: movies.find( { “cast”: “Salma Hayek” } ) ...
Read more >
Mongoose v6.8.2: Deprecation Warnings
DeprecationWarning : collection.count is deprecated, and will be removed in a future version. Use collection.countDocuments or collection.
Read more >
collection.count is deprecated, and will be removed in a future ...
nodejs操作mongodb 用db.collection(collectionName).count(json)报错如下: nodejs操作mongodb报错(node:664) DeprecationWarning: collection.count is deprecated, ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found