To log all queries that Mongoose fire in the application with JavaScript, we call the set
method.
For instance, we write
mongoose.set("debug", (collectionName, method, query, doc) => {
console.log(`${collectionName}.${method}`, JSON.stringify(query), doc);
});
to call set
with a callback to log the values from the query.
We log the collectionName
collection, method
that’s called, the query
made, and the doc
results returned.