Gathering detailed insights and metrics for mongoose-query-logger
Gathering detailed insights and metrics for mongoose-query-logger
Gathering detailed insights and metrics for mongoose-query-logger
Gathering detailed insights and metrics for mongoose-query-logger
npm install mongoose-query-logger
Typescript
Module System
Min. Node Version
TypeScript (99.77%)
JavaScript (0.23%)
Total Downloads
362,688
Last Day
220
Last Week
1,007
Last Month
6,007
Last Year
71,316
7 Stars
35 Commits
3 Forks
2 Watching
1 Branches
2 Contributors
Latest Version
0.2.3
Package Id
mongoose-query-logger@0.2.3
Unpacked Size
307.28 kB
Size
82.48 kB
File Count
26
Cumulative downloads
Total Downloads
Last day
32.5%
220
Compared to previous day
Last week
-26.1%
1,007
Compared to previous week
Last month
12.3%
6,007
Compared to previous month
Last year
7.3%
71,316
Compared to previous year
1
2
Mongoose middleware to log your mongoose queries and execution timings.
Optionally, it also logs index usage and warns you about full collection scans
npm install --save-dev mongoose-query-logger
Apply the plugin to all schemas:
1import { MongooseQueryLogger } from 'mongoose-query-logger'; 2 3export const queryLogger = new MongooseQueryLogger(); 4 5// optionally add custom configuration eg: 6// queryLogger 7// .setExplain(true) 8// .setAdditionalLogProperties(true) 9// .setQueryLogger(myCustomQueryLogger) 10// .setExplainLogger(myCustomExplainLogger); 11 12mongoose.plugin(queryLogger.getPlugin());
Apply the plugin to specific schemas:
1import { MongooseQueryLogger } from 'mongoose-query-logger'; 2 3export const queryLogger = new MongooseQueryLogger(); 4 5// optionally add custom configuration eg: 6// queryLogger 7// .setExplain(true) 8// .setAdditionalLogProperties(true) 9// .setQueryLogger(myCustomQueryLogger) 10// .setExplainLogger(myCustomExplainLogger); 11 12const schema = new mongoose.Schema({ 13 /* schema definition */ 14}); 15 16schema.plugin(queryLogger.getPlugin()); 17 18// compile the model AFTER registering plugins 19const User = mongoose.model('User', schema);
This is turned off by default. It will fire an explain query for supported operations. Turn this on by calling:
plugin.setExplain(true)
warning: don't use explain
in production, it will run each query twice.
The following methods are supported for query logging
method | supported |
---|---|
count | :heavy_check_mark: |
countDocuments | :heavy_check_mark: |
estimatedDocumentCount | :heavy_check_mark: |
find | :heavy_check_mark: |
findOne | :heavy_check_mark: |
findOneAndUpdate | :heavy_check_mark: |
findOneAndRemove | :heavy_check_mark: |
findOneAndDelete | :heavy_check_mark: |
findOneAndRemove | :heavy_check_mark: |
update | :heavy_check_mark: |
updateOne | :heavy_check_mark: |
updateMany | :heavy_check_mark: |
deleteOne | :heavy_check_mark: |
deleteMany | :heavy_check_mark: |
aggregate | :heavy_check_mark: |
remove | |
insertMany | |
distinct |
If you want only a subset of these to be logged, you can provide an array of supported methods like so:
plugin.setQueryMethods({targetMethods: ['find', 'aggregate']})
The following methods are supported for query explaining
method | supported |
---|---|
find | :heavy_check_mark: |
findOne | :heavy_check_mark: |
aggregate | :heavy_check_mark: |
If you want only a subset of these to be logged, you can provide an array of supported methods like so:
plugin.setQueryMethods({explainMethods: ['find', 'aggregate']})
You can provide a custom logging function by calling plugin.setQueryLogger(myCustomLogger)
The logger should be a function that accepts a single argument of type object with the following keys:
key | type | description | example |
---|---|---|---|
operation | string | executed operation | find, aggregate |
collectionName | string | collection name | tasks |
executionTimeMS | number | query execution time in ms | 320ms |
filter | Object or null | filter object provided to the query | {"name": "john"} |
fields | Object or null | projection fields | {"name": 1} |
options | any | query options | {"sort": "name"} |
update | Object or null | ||
additionalLogProperties | any | additional log options |
You can provide a custom explain logging function by calling plugin.setExplainLogger(myCustomExplainLogger)
The logger should be a function that accepts a single argument of type object with the following keys:
key | type | description |
---|---|---|
queryPlanners | any[] | array of query execution plans as returned from mongodb |
You can include additional metadata in your queries by turning this on with
plugin.setAdditionalLogProperties(true)
and using it like await User.find({"name": "john"}).additionalLogProperties('something')
This was tested under mongoose 4.4 and node.js >= 12
MIT © Federico Marcos
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
no dangerous workflow patterns detected
Reason
license file detected
Details
Reason
Found 0/30 approved changesets -- score normalized to 0
Reason
no SAST tool detected
Details
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
detected GitHub workflow tokens with excessive permissions
Details
Reason
dependency not pinned by hash detected -- score normalized to 0
Details
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
Reason
project is not fuzzed
Details
Reason
branch protection not enabled on development/release branches
Details
Reason
70 existing vulnerabilities detected
Details
Score
Last Scanned on 2024-12-30
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More