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.

`Collection.count` is deprecated but `Collection.countDocuments` and `Collection.estimatedDocumentCount` are not functions

See original GitHub issue

Hi!

I’m having trouble trying to count items in a collection. The current documentation says that you have to use the method count in a collection, but when I use it, it throws a deprecation message:

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

but when I try to use any of the recommended methods, both throw an exception:

TypeError: myCollection.countDocuments is not a function
TypeError: myCollection.estimatedDocumentCount is not a function

I’m using monk version 7.1.2:

{
  "dependencies": {
    "monk": "^7.1.2"
  }
}

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
mathieudutourcommented, Mar 2, 2020

Because nobody sent a PR to support them!

Happy to review and merge one if you want to work on it 👍

1reaction
jeancarlozapatacommented, Feb 21, 2020

@osban you are correct, the deprecation notice is coming from Mongo itself. The problem was yesterday it was returning undefined instead of the count. Not sure why it wasn’t working. I reinstalled my local mongodb instance, used the same code and now it’s all working fine.

False alarm 😅 sorry and thank you for your answer!

Read more comments on GitHub >

github_iconTop Results From Across the Web

mongodb-nodejs-driver, DeprecationWarning: collection.count ...
The underlying mongodb driver has deprecated the .count() method.You should use .estimatedDocumentCount() or .countDocuments() instead.
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 >
Nodejs FindCursor#count deprecation replacement ...
I first tried using FindCursor#count , but unfortunately, it is deprecated. In this question and the warning message, collection.countDocuments ...
Read more >
Migrating obsolete "Count" to new methods has a problematic ...
When you call EstimatedDocumentCount, the driver or shell sends the count command without a predicate, which uses the collection metadata to ...
Read more >
Mongoose v6.8.1: Deprecation Warnings
Replace count() with countDocuments() , unless you want to count how many documents are in the whole collection (no filter). In the latter...
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