How to get the last 10 query run on MongoDB?

Posted on

Question :

I am using mongoose driver in my Node.js app and I want to know what queries mongoose run behind the scene when I call available function on mongoose model.

e.g. I am saving a signup information for a user using mongoose create function and as per its definition: it should create the document in the database with the provided information. It returns a document to the caller, so I am curious to know whether it run extra query to get the returned document or it makes it from the provided information. In the first case it will take a network bandwidth for the already available information so I want to avoid this by using any other function but I don’t think it is working like this.

Anyway, please suggest me how can I see the last 10 queries that hits MongoDB Database?

Answer :

On the database side, you can enable Auditing, but at this time, only available on MongoDB Enterprise.

Leave a Reply

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