`Collection.count` is deprecated but `Collection.countDocuments` and `Collection.estimatedDocumentCount` are not functions
See original GitHub issueHi!
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:
- Created 4 years ago
- Comments:5 (2 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Because nobody sent a PR to support them!
Happy to review and merge one if you want to work on it 👍
@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 localmongodb
instance, used the same code and now it’s all working fine.False alarm 😅 sorry and thank you for your answer!