I’ve searched for this several times over the last year or two, and each time it takes me a while to find the solution. If you’re looking for the last queries that were executed against your MongoDB instance, these are the steps you need to perform:

Enable The Profiler

First, enable the profiler by executing the following command:

db.setProfilingLevel(2);

Keep in mind that this has an impact on performance. Best not to do this on the production database.

If you want to know what the original value was first, you can see it in the output of the above command or just run this command first:

db.getProfilingLevel();

Check The Queries

Now you can see the last commands that MongoDB received by running:

db.getCollection('system.profile').find({});

Clean Up

Don’t forget to set the profiling level back to 0:

db.setProfilingLevel(0);

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes:

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

This site uses Akismet to reduce spam. Learn how your comment data is processed.