Count documents for a specific filter.
Section: Create and read
Count matching documents
javascript
javascript
db.products.countDocuments({ in_stock: true })Explanation
Prefer `countDocuments()` for an accurate filtered count.
Learn the surrounding workflow
Compare similar commands or jump into common fixes when this command is part of a bigger troubleshooting path.
Related commands
Same sheet · prioritizing Create and read