setVerboseShell()
On this page
MongoDB 5.0 is end of life as of October 2024. This version of the documentation is no longer
supported. To upgrade your 5.0 deployment, see the MongoDB 6.0 upgrade procedures.
Note
The native method listed here is for the legacy mongo
shell.
To use native methods in mongosh
, see
Native Methods in mongosh
.
setVerboseShell()
The
setVerboseShell()
method configuresmongosh
to print the duration of each operation.setVerboseShell()
has the form:setVerboseShell(true) setVerboseShell()
takes one boolean parameter. Specifytrue
or leave the parameter blank to activate the verbose shell. Specifyfalse
to deactivate.
Example
The following example demonstrates the behavior of the verbose shell:
From
mongosh
, set verbose shell totrue
:setVerboseShell(true) With verbose shell set to
true
, rundb.collection.aggregate()
:db.restaurants.aggregate( [ { $match: { "borough": "Queens", "cuisine": "Brazilian" } }, { $group: { "_id": "$address.zipcode" , "count": { $sum: 1 } } } ] ); In addition to returning the results of the operation,
mongosh
now displays information about the duration of the operation:{ "_id" : "11377", "count" : 1 } { "_id" : "11368", "count" : 1 } { "_id" : "11101", "count" : 2 } { "_id" : "11106", "count" : 3 } { "_id" : "11103", "count" : 1 } Fetched 5 record(s) in 0ms