db.stats() — MongoDB Technical Interview Questions & Answers
Shows storage statistics for the current database.
db.stats()
- Simple meaning: db.stats() prints size, collection count, and object count for the current database.
- How to use: use college then db.stats(). Collection: db.students.stats().
- Try this: insert 3 students, run db.stats(), look at objects.
- Common mistake: treating it as a query of student rows — it is storage stats, not find().
- Interview tip: “Health/size snapshot, not business data.”
Technical Interview Tip: stats() = storage numbers, find() = documents.
Code Examples for db.stats()
db.stats() — working example
db.stats()
db.users.stats()db.stats() — stats() reports storage counts/sizes for a database or collection.
How to Explain db.stats() to an Interviewer
What is db.stats()?
Storage and count statistics for the current database