Search code examples
mysqlmongodbexplaindatabasenosql

Time taken for operation MongoDB


When performing an operation using MySQL, the following output is displayed:

Query OK, 996 rows affected (0.03 sec)

This was from deleting 996 records. Is there a way of attaining similar information when performing operations using MongoDB? I am particularly interested in the time taken.

Something similar to the .explain() flag but for removing or deleting records.


Solution

  • You can use setVerboseShell(true) in the mongo shell:

    > setVerboseShell(true)
    
    > db.testing.update({}, {$set: { deleteme: true }}, { multi:true })
    Updated 100 existing record(s) in 1ms
    WriteResult({ "nMatched" : 100, "nUpserted" : 0, "nModified" : 100 })
    
    > db.testing.remove({ deleteme:true })
    Removed 100 record(s) in 1ms
    WriteResult({ "nRemoved" : 100 })
    

    If you want this to be your default, you can add setVerboseShell(true) to your ~/.mongorc.js file (which will be loaded when the mongo shell starts).