Mongoose: Print database name in debug

Created on 1 Apr 2020  路  2Comments  路  Source: Automattic/mongoose

I am using multiple MongoDB connection with debug mode enabled. Is there a way to log the database name in debug log?

help

Most helpful comment

Not currently, you would need a custom debug function. Here's a quick proof of concept for printing out the database name and collection name in a custom debug function:

mongoose.set('debug', function(collectionName, op) {
  console.log(`${this.conn.name}.${collectionName}.${op}()`);
});

All 2 comments

Not currently, you would need a custom debug function. Here's a quick proof of concept for printing out the database name and collection name in a custom debug function:

mongoose.set('debug', function(collectionName, op) {
  console.log(`${this.conn.name}.${collectionName}.${op}()`);
});
Was this page helpful?
0 / 5 - 0 ratings