mongosh --eval 'db.stats()'

Category: Databases & SQL

mongosh --eval 'db.stats()'

Run a shell expression and exit

--eval executes the JavaScript expression against the default local server and exits, which is great for scripts. db.stats() reports storage size and object counts for the current database. Related: mongosh --file for longer scripts.
Looking for more? Search all 7,657 commands — works offline, in English or Spanish, and fixes typos.