log all queries that mongoose fire in the application

前端 未结 4 1990
忘了有多久
忘了有多久 2020-12-04 09:52

I have application using nodejs and mongodb. I have used mongoose for ODM. Now i want to log all the queries that mongoose fire during the whole application.

How to

4条回答
  •  情深已故
    2020-12-04 10:13

    You can use the following format:

    mongoose.set("debug", (collectionName, method, query, doc) => {
        console.log(`${collectionName}.${method}`, JSON.stringify(query), doc);
    });
    

    or any other logger of your choice:

    mongoose.set("debug", (collectionName, method, query, doc) => {
        logger(`${collectionName}.${method}`, JSON.stringify(query), doc);
    });
    

提交回复
热议问题