Installations
npm install mongoose-query-logger
Developer Guide
Typescript
No
Module System
CommonJS
Min. Node Version
>=10
Releases
Unable to fetch releases
Contributors
Unable to fetch Contributors
Languages
TypeScript (99.77%)
JavaScript (0.23%)
Developer
marcosfede
Download Statistics
Total Downloads
362,688
Last Day
220
Last Week
1,007
Last Month
6,007
Last Year
71,316
GitHub Statistics
7 Stars
35 Commits
3 Forks
2 Watching
1 Branches
2 Contributors
Package Meta Information
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
Total Downloads
Cumulative downloads
Total Downloads
362,688
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
Daily Downloads
Weekly Downloads
Monthly Downloads
Yearly Downloads
Dependencies
1
Peer Dependencies
2
Mongoose Query Logger
Mongoose middleware to log your mongoose queries and execution timings.
Optionally, it also logs index usage and warns you about full collection scans
Screenshots
Query logging and execution timing
Query Explain
Installation
npm install --save-dev mongoose-query-logger
Usage
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);
Explain logging
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.
Supported query logging methods
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']})
Supported explain logging methods
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']})
Custom query logger
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 |
Custom explain logger
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 |
Additional log properties
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')
Supported versions
This was tested under mongoose 4.4 and node.js >= 12
License
MIT © Federico Marcos
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
no dangerous workflow patterns detected
Reason
license file detected
Details
- Info: project has a license file: LICENSE:0
- Info: FSF or OSI recognized license: MIT License: LICENSE:0
Reason
Found 0/30 approved changesets -- score normalized to 0
Reason
no SAST tool detected
Details
- Warn: no pull requests merged into dev branch
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
- Warn: no topLevel permission defined: .github/workflows/main.yml:1
- Warn: no topLevel permission defined: .github/workflows/size.yml:1
- Info: no jobLevel write permissions found
Reason
dependency not pinned by hash detected -- score normalized to 0
Details
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/main.yml:31: update your workflow using https://app.stepsecurity.io/secureworkflow/marcosfede/mongoose-query-logger/main.yml/master?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/main.yml:34: update your workflow using https://app.stepsecurity.io/secureworkflow/marcosfede/mongoose-query-logger/main.yml/master?enable=pin
- Warn: third-party GitHubAction not pinned by hash: .github/workflows/main.yml:39: update your workflow using https://app.stepsecurity.io/secureworkflow/marcosfede/mongoose-query-logger/main.yml/master?enable=pin
- Warn: third-party GitHubAction not pinned by hash: .github/workflows/main.yml:44: update your workflow using https://app.stepsecurity.io/secureworkflow/marcosfede/mongoose-query-logger/main.yml/master?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/size.yml:9: update your workflow using https://app.stepsecurity.io/secureworkflow/marcosfede/mongoose-query-logger/size.yml/master?enable=pin
- Warn: third-party GitHubAction not pinned by hash: .github/workflows/size.yml:10: update your workflow using https://app.stepsecurity.io/secureworkflow/marcosfede/mongoose-query-logger/size.yml/master?enable=pin
- Info: 0 out of 3 GitHub-owned GitHubAction dependencies pinned
- Info: 0 out of 3 third-party GitHubAction dependencies pinned
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
- Warn: no security policy file detected
- Warn: no security file to analyze
- Warn: no security file to analyze
- Warn: no security file to analyze
Reason
project is not fuzzed
Details
- Warn: no fuzzer integrations found
Reason
branch protection not enabled on development/release branches
Details
- Warn: branch protection not enabled for branch 'master'
Reason
70 existing vulnerabilities detected
Details
- Warn: Project is vulnerable to: GHSA-67hx-6x53-jw92
- Warn: Project is vulnerable to: GHSA-93q8-gq69-wqmw
- Warn: Project is vulnerable to: GHSA-qwcr-r2fm-qrc7
- Warn: Project is vulnerable to: GHSA-grv7-fg5c-xmjg
- Warn: Project is vulnerable to: GHSA-x9w5-v3q2-3rhw
- Warn: Project is vulnerable to: GHSA-w8qv-6jwh-64r5
- Warn: Project is vulnerable to: GHSA-257v-vj4p-3w2h
- Warn: Project is vulnerable to: GHSA-pxg6-pf52-xh8x
- Warn: Project is vulnerable to: GHSA-3xgq-45jj-v275
- Warn: Project is vulnerable to: GHSA-gxpj-cx7g-858c
- Warn: Project is vulnerable to: GHSA-w573-4hg7-7wgq
- Warn: Project is vulnerable to: GHSA-phwq-j96m-2c2q
- Warn: Project is vulnerable to: GHSA-ghr5-ch3p-vcr6
- Warn: Project is vulnerable to: GHSA-r9p9-mrjm-926w
- Warn: Project is vulnerable to: GHSA-434g-2637-qmqr
- Warn: Project is vulnerable to: GHSA-49q7-c7j4-3p7m
- Warn: Project is vulnerable to: GHSA-977x-g7h5-7qgw
- Warn: Project is vulnerable to: GHSA-f7q4-pwc6-w24p
- Warn: Project is vulnerable to: GHSA-fc9h-whq2-v747
- Warn: Project is vulnerable to: GHSA-rv95-896h-c2vc
- Warn: Project is vulnerable to: GHSA-qw6h-vgh9-j6wx
- Warn: Project is vulnerable to: GHSA-ww39-953v-wcq6
- Warn: Project is vulnerable to: GHSA-43f8-2h32-f4cj
- Warn: Project is vulnerable to: GHSA-7r28-3m3f-r2pr
- Warn: Project is vulnerable to: GHSA-r8j5-h5cx-65gg
- Warn: Project is vulnerable to: GHSA-896r-f27r-55mw
- Warn: Project is vulnerable to: GHSA-9c47-m6qq-7p4h
- Warn: Project is vulnerable to: GHSA-76p3-8jx3-jpfq
- Warn: Project is vulnerable to: GHSA-3rfm-jhwj-7488
- Warn: Project is vulnerable to: GHSA-hhq3-ff78-jv3g
- Warn: Project is vulnerable to: GHSA-29mw-wpgm-hmr9
- Warn: Project is vulnerable to: GHSA-35jh-r3h4-6jhm
- Warn: Project is vulnerable to: GHSA-952p-6rrq-rcjv
- Warn: Project is vulnerable to: GHSA-f8q6-p94x-37v3
- Warn: Project is vulnerable to: GHSA-xvch-5gv4-984h
- Warn: Project is vulnerable to: GHSA-vxvm-qww3-2fh7
- Warn: Project is vulnerable to: GHSA-f825-f98c-gj3g
- Warn: Project is vulnerable to: GHSA-h8hf-x3f4-xwgp
- Warn: Project is vulnerable to: GHSA-9m93-w8w6-76hh
- Warn: Project is vulnerable to: GHSA-m7xq-9374-9rvx
- Warn: Project is vulnerable to: GHSA-p92x-r36w-9395
- Warn: Project is vulnerable to: GHSA-45q2-34rf-mr94
- Warn: Project is vulnerable to: GHSA-qrpm-p2h7-hrv2
- Warn: Project is vulnerable to: GHSA-mwcw-c2x4-8c55
- Warn: Project is vulnerable to: GHSA-5fw9-fq32-wv5p
- Warn: Project is vulnerable to: GHSA-rp65-9cf3-cjxr
- Warn: Project is vulnerable to: GHSA-hj48-42vr-x3v9
- Warn: Project is vulnerable to: GHSA-9wv6-86v2-598j
- Warn: Project is vulnerable to: GHSA-rhx6-c78j-4q9w
- Warn: Project is vulnerable to: GHSA-566m-qj78-rww5
- Warn: Project is vulnerable to: GHSA-hwj9-h5mp-3pm3
- Warn: Project is vulnerable to: GHSA-7fh5-64p2-3v2j
- Warn: Project is vulnerable to: GHSA-hrpp-h998-j3pp
- Warn: Project is vulnerable to: GHSA-p8p7-x288-28g6
- Warn: Project is vulnerable to: GHSA-gcx4-mw62-g8wm
- Warn: Project is vulnerable to: GHSA-c2qf-rxjj-qqgw
- Warn: Project is vulnerable to: GHSA-44c6-4v22-4mhx
- Warn: Project is vulnerable to: GHSA-4x5v-gmq8-25ch
- Warn: Project is vulnerable to: GHSA-m6fv-jmcg-4jfg
- Warn: Project is vulnerable to: GHSA-cm22-4g7w-348p
- Warn: Project is vulnerable to: GHSA-4rq4-32rv-6wp6
- Warn: Project is vulnerable to: GHSA-64g7-mvw6-v9qj
- Warn: Project is vulnerable to: GHSA-vx3p-948g-6vhq
- Warn: Project is vulnerable to: GHSA-4wf5-vphf-c2xc
- Warn: Project is vulnerable to: GHSA-jgrx-mgxx-jf9v
- Warn: Project is vulnerable to: GHSA-72xf-g2v4-qvf3
- Warn: Project is vulnerable to: GHSA-j8xg-fqg3-53r7
- Warn: Project is vulnerable to: GHSA-6fc8-4gx4-v693
- Warn: Project is vulnerable to: GHSA-3h5v-q93c-6h6q
- Warn: Project is vulnerable to: GHSA-c4w7-xm78-47vh
Score
2.5
/10
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