├── .gitignore ├── .npmignore ├── LICENSE ├── README.md ├── example ├── app.js ├── package-lock.json └── package.json ├── index.ts ├── package-lock.json ├── package.json └── tsconfig.json /.gitignore: -------------------------------------------------------------------------------- 1 | lib-cov 2 | *.seed 3 | *.log 4 | *.csv 5 | *.dat 6 | *.out 7 | *.pid 8 | *.gz 9 | *.swp 10 | 11 | pids 12 | logs 13 | results 14 | tmp 15 | 16 | # Build 17 | public/css/main.css 18 | 19 | # Coverage reports 20 | coverage 21 | 22 | # API keys and secrets 23 | .env 24 | 25 | # Dependency directory 26 | node_modules 27 | bower_components 28 | 29 | # Editors 30 | .idea 31 | *.iml 32 | 33 | # OS metadata 34 | .DS_Store 35 | Thumbs.db 36 | 37 | # Ignore built ts files 38 | dist 39 | 40 | # ignore yarn.lock 41 | yarn.lock 42 | 43 | -------------------------------------------------------------------------------- /.npmignore: -------------------------------------------------------------------------------- 1 | example -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2020 Hamza Sabljakovic 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | 2 | # Mongoose execution time 3 | 4 | Mongoose plugin for measuring and logging query execution time. 5 | 6 | ```bash 7 | npm i mongoose-execution-time 8 | ``` 9 | 10 | Output example: 11 | 12 | ```sh 13 | Query: find in customers completed in: 7 ms { filter: {} } 14 | 15 | Query: find in blogposts completed in: 4 ms { filter: { title: 'Post 1' }, 16 | additionalLogProperties: { bruh: 1 } } 17 | 18 | Query: findOne in blogposts completed in: 4 ms { filter: {} } 19 | 20 | Query: estimatedDocumentCount in blogposts completed in: 3 ms { filter: {} } 21 | 22 | Query: aggregate in blogposts completed in: 1 ms { aggregatePipeline: '[{"$match":{"title":"Post 1"}}]' } 23 | 24 | Query: aggregate in blogposts completed in: 1 ms { 25 | aggregatePipeline: '[{"$match":{"title":"Post 1"}},{"$project":{"title":1}}]' 26 | } 27 | 28 | 29 | ``` 30 | 31 | ## How to use 32 | 33 | ```js 34 | const mongoose = require('mongoose'); 35 | const { logExecutionTime } = require('mongoose-execution-time'); 36 | 37 | mongoose.plugin(logExecutionTime); 38 | ``` 39 | 40 | 41 | ## Configuration 42 | 43 | 44 | The plugin can be easily adjusted via the following configuration options. 45 | 46 | ```ts 47 | interface LogExecutionTimeConfig { 48 | logger?: any; 49 | loggerLevel?: string; 50 | loggerVerbosity?: LoggerVerbosity; 51 | loggerFunction?: LoggerFunction; 52 | } 53 | ``` 54 | 55 | 56 | | Option | Description | Default | 57 | |---|---|---| 58 | | logger | logger provider | console | 59 | | loggerLevel | logger level used by the logger above | debug | 60 | | loggerVerbosity | controls how much information gets logged | High | 61 | | loggerFunction | for full control over how the log gets written | N/A | 62 | 63 | 64 | Code example: 65 | 66 | ```js 67 | const mongoose = require('mongoose'); 68 | const { logExecutionTime } = require('mongoose-execution-time'); 69 | 70 | mongoose.plugin(logExecutionTime, { 71 | loggerLevel: 'info' 72 | }); 73 | ``` 74 | ## Do not want filter/aggregatePipeline information logged? 75 | 76 | Simply set the `loggerVerbosity` to `LoggerVerbosity.Normal` in the plugin configuration. 77 | 78 | ```js 79 | const mongoose = require('mongoose'); 80 | const { logExecutionTime, LoggerVerbosity } = require('mongoose-execution-time'); 81 | 82 | mongoose.plugin(logExecutionTime, { 83 | loggerVerbosity: LoggerVerbosity.Normal, 84 | loggerLevel: 'info' 85 | }); 86 | ``` 87 | 88 | ## Logging additional information 89 | 90 | The plugin exposes a method for logging additional information in the same log line as the execution time. 91 | 92 | Code example: 93 | 94 | ```ts 95 | await BlogPostModel.find({ title: 'Title' }).additionalLogProperties({ message: 'My custom message'}); 96 | ``` 97 | 98 | Output example: 99 | 100 | ``` 101 | Query: find in blogposts completed in: 8 ms { additionalLogProperties: { message: 'My custom message' } } 102 | ``` 103 | 104 | ## Log message configuration 105 | 106 | If the default logger formatting or style doesn't fit your needs, it can be adjusted by providing a custom logger function. 107 | 108 | Code example: 109 | 110 | ```ts 111 | const mongoose = require('mongoose'); 112 | const { logExecutionTime } = require('mongoose-execution-time'); 113 | 114 | mongoose.plugin(logExecutionTime, { 115 | loggerFunction: (operation, collectionName, executionTimeMS, filter, update, additionalLogProperties, aggregationPipeline) => { 116 | console.log(`My custom logger function | ${operation} | ${collectionName} | ${executionTimeMS}`, { filter, update, additionalLogProperties, aggregationPipeline }) 117 | } 118 | }); 119 | ``` 120 | 121 | Output example: 122 | 123 | ``` 124 | My custom logger function | find | blogposts | 4 { 125 | filter: { title: 'Post 1' }, 126 | update: undefined, 127 | additionalLogProperties: { bruh: 1 } 128 | aggregationPipeline: null 129 | } 130 | ``` -------------------------------------------------------------------------------- /example/app.js: -------------------------------------------------------------------------------- 1 | const mongoose = require('mongoose'); 2 | const { logExecutionTime, LoggerVerbosity } = require('mongoose-execution-time'); 3 | 4 | mongoose.plugin(logExecutionTime, { 5 | // loggerFunction: (operation, collectionName, executionTimeMS, filter, update, additionalLogProperties) => { 6 | // console.log(`My custom logger function | ${operation} | ${collectionName} | ${executionTimeMS}`, { filter, update, additionalLogProperties }) 7 | // } 8 | // loggerVerbosity: LoggerVerbosity.Normal, 9 | }); 10 | 11 | const Schema = mongoose.Schema; 12 | 13 | const BlogPost = new Schema({ 14 | title: String, 15 | body: String, 16 | }); 17 | 18 | const Customer = new Schema({ 19 | customerId: String, 20 | name: String 21 | }) 22 | 23 | 24 | const BlogPostModel = mongoose.model('blogPost', BlogPost); 25 | const CustomerModel = mongoose.model('customer', Customer); 26 | 27 | 28 | 29 | const run = async () => { 30 | 31 | console.log('Running...') 32 | 33 | await mongoose.connect('mongodb://localhost:27017/my_database', { 34 | useNewUrlParser: true, 35 | useUnifiedTopology: true, 36 | useFindAndModify: false 37 | }); 38 | 39 | await BlogPostModel.insertMany([{ 40 | title: 'Post 1', 41 | body: 'Body 1' 42 | }]) 43 | 44 | 45 | await BlogPostModel.find({ title: 'Title' }).additionalLogProperties({ message: 'My custom message'}); 46 | 47 | await CustomerModel.find({}); 48 | 49 | 50 | await new BlogPostModel({title: 'SAVED'}).save(); 51 | 52 | await BlogPostModel.find({ title: 'Post 1' }).additionalLogProperties({bruh: 1}); 53 | await BlogPostModel.findOne(); 54 | 55 | // await BlogPostModel.count({ title: 'Post 1' }); 56 | await BlogPostModel.estimatedDocumentCount({ title: 'Post 1' }); 57 | await BlogPostModel.countDocuments({ title: 'Post 1' }); 58 | await BlogPostModel.findOneAndUpdate({ title: 'Post 1' }, { title: 'updated' }) 59 | await BlogPostModel.findOneAndDelete({ title: 'Post 1' }) 60 | await BlogPostModel.findOneAndRemove({ title: 'Post 1' }) 61 | await BlogPostModel.deleteOne({ title: 'Post 1' }) 62 | await BlogPostModel.deleteMany({ title: 'Post 1' }) 63 | // await BlogPostModel.remove({ title: 'Post 1' }) 64 | 65 | await BlogPostModel.aggregate([{$match: {title: 'Post 1'}}]) 66 | await BlogPostModel.aggregate([{ $match: { title: 'Post 1' } }, { $project: { title: 1 } }]) 67 | console.log('Completed') 68 | } 69 | 70 | run().then(_ => console.log('Executed')); 71 | 72 | -------------------------------------------------------------------------------- /example/package-lock.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "mongoose-execution-time-example", 3 | "version": "1.0.0", 4 | "lockfileVersion": 2, 5 | "requires": true, 6 | "packages": { 7 | "": { 8 | "name": "mongoose-execution-time-example", 9 | "version": "1.0.0", 10 | "license": "ISC", 11 | "dependencies": { 12 | "mongoose": "^5.9.20", 13 | "mongoose-execution-time": "1.1.0" 14 | } 15 | }, 16 | "../dist/index.js": { 17 | "extraneous": true 18 | }, 19 | "node_modules/@types/bson": { 20 | "version": "4.0.5", 21 | "resolved": "https://registry.npmjs.org/@types/bson/-/bson-4.0.5.tgz", 22 | "integrity": "sha512-vVLwMUqhYJSQ/WKcE60eFqcyuWse5fGH+NMAXHuKrUAPoryq3ATxk5o4bgYNtg5aOM4APVg7Hnb3ASqUYG0PKg==", 23 | "dependencies": { 24 | "@types/node": "*" 25 | } 26 | }, 27 | "node_modules/@types/mongodb": { 28 | "version": "3.6.20", 29 | "resolved": "https://registry.npmjs.org/@types/mongodb/-/mongodb-3.6.20.tgz", 30 | "integrity": "sha512-WcdpPJCakFzcWWD9juKoZbRtQxKIMYF/JIAM4JrNHrMcnJL6/a2NWjXxW7fo9hxboxxkg+icff8d7+WIEvKgYQ==", 31 | "dependencies": { 32 | "@types/bson": "*", 33 | "@types/node": "*" 34 | } 35 | }, 36 | "node_modules/@types/node": { 37 | "version": "20.4.2", 38 | "resolved": "https://registry.npmjs.org/@types/node/-/node-20.4.2.tgz", 39 | "integrity": "sha512-Dd0BYtWgnWJKwO1jkmTrzofjK2QXXcai0dmtzvIBhcA+RsG5h8R3xlyta0kGOZRNfL9GuRtb1knmPEhQrePCEw==" 40 | }, 41 | "node_modules/bl": { 42 | "version": "2.2.1", 43 | "resolved": "https://registry.npmjs.org/bl/-/bl-2.2.1.tgz", 44 | "integrity": "sha512-6Pesp1w0DEX1N550i/uGV/TqucVL4AM/pgThFSN/Qq9si1/DF9aIHs1BxD8V/QU0HoeHO6cQRTAuYnLPKq1e4g==", 45 | "dependencies": { 46 | "readable-stream": "^2.3.5", 47 | "safe-buffer": "^5.1.1" 48 | } 49 | }, 50 | "node_modules/bluebird": { 51 | "version": "3.5.1", 52 | "resolved": "https://registry.npmjs.org/bluebird/-/bluebird-3.5.1.tgz", 53 | "integrity": "sha512-MKiLiV+I1AA596t9w1sQJ8jkiSr5+ZKi0WKrYGUn6d1Fx+Ij4tIj+m2WMQSGczs5jZVxV339chE8iwk6F64wjA==" 54 | }, 55 | "node_modules/bson": { 56 | "version": "1.1.6", 57 | "resolved": "https://registry.npmjs.org/bson/-/bson-1.1.6.tgz", 58 | "integrity": "sha512-EvVNVeGo4tHxwi8L6bPj3y3itEvStdwvvlojVxxbyYfoaxJ6keLgrTuKdyfEAszFK+H3olzBuafE0yoh0D1gdg==", 59 | "engines": { 60 | "node": ">=0.6.19" 61 | } 62 | }, 63 | "node_modules/core-util-is": { 64 | "version": "1.0.3", 65 | "resolved": "https://registry.npmjs.org/core-util-is/-/core-util-is-1.0.3.tgz", 66 | "integrity": "sha512-ZQBvi1DcpJ4GDqanjucZ2Hj3wEO5pZDS89BWbkcrvdxksJorwUDDZamX9ldFkp9aw2lmBDLgkObEA4DWNJ9FYQ==" 67 | }, 68 | "node_modules/debug": { 69 | "version": "3.1.0", 70 | "resolved": "https://registry.npmjs.org/debug/-/debug-3.1.0.tgz", 71 | "integrity": "sha512-OX8XqP7/1a9cqkxYw2yXss15f26NKWBpDXQd0/uK/KPqdQhxbPa994hnzjcE2VqQpDslf55723cKPUOGSmMY3g==", 72 | "dependencies": { 73 | "ms": "2.0.0" 74 | } 75 | }, 76 | "node_modules/debug/node_modules/ms": { 77 | "version": "2.0.0", 78 | "resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz", 79 | "integrity": "sha512-Tpp60P6IUJDTuOq/5Z8cdskzJujfwqfOTkrwIwj7IRISpnkJnT6SyJ4PCPnGMoFjC9ddhal5KVIYtAt97ix05A==" 80 | }, 81 | "node_modules/denque": { 82 | "version": "1.5.1", 83 | "resolved": "https://registry.npmjs.org/denque/-/denque-1.5.1.tgz", 84 | "integrity": "sha512-XwE+iZ4D6ZUB7mfYRMb5wByE8L74HCn30FBN7sWnXksWc1LO1bPDl67pBR9o/kC4z/xSNAwkMYcGgqDV3BE3Hw==", 85 | "engines": { 86 | "node": ">=0.10" 87 | } 88 | }, 89 | "node_modules/inherits": { 90 | "version": "2.0.4", 91 | "resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.4.tgz", 92 | "integrity": "sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ==" 93 | }, 94 | "node_modules/isarray": { 95 | "version": "1.0.0", 96 | "resolved": "https://registry.npmjs.org/isarray/-/isarray-1.0.0.tgz", 97 | "integrity": "sha512-VLghIWNM6ELQzo7zwmcg0NmTVyWKYjvIeM83yjp0wRDTmUnrM678fQbcKBo6n2CJEF0szoG//ytg+TKla89ALQ==" 98 | }, 99 | "node_modules/kareem": { 100 | "version": "2.3.2", 101 | "resolved": "https://registry.npmjs.org/kareem/-/kareem-2.3.2.tgz", 102 | "integrity": "sha512-STHz9P7X2L4Kwn72fA4rGyqyXdmrMSdxqHx9IXon/FXluXieaFA6KJ2upcHAHxQPQ0LeM/OjLrhFxifHewOALQ==" 103 | }, 104 | "node_modules/memory-pager": { 105 | "version": "1.5.0", 106 | "resolved": "https://registry.npmjs.org/memory-pager/-/memory-pager-1.5.0.tgz", 107 | "integrity": "sha512-ZS4Bp4r/Zoeq6+NLJpP+0Zzm0pR8whtGPf1XExKLJBAczGMnSi3It14OiNCStjQjM6NU1okjQGSxgEZN8eBYKg==", 108 | "optional": true 109 | }, 110 | "node_modules/mongodb": { 111 | "version": "3.7.4", 112 | "resolved": "https://registry.npmjs.org/mongodb/-/mongodb-3.7.4.tgz", 113 | "integrity": "sha512-K5q8aBqEXMwWdVNh94UQTwZ6BejVbFhh1uB6c5FKtPE9eUMZPUO3sRZdgIEcHSrAWmxzpG/FeODDKL388sqRmw==", 114 | "dependencies": { 115 | "bl": "^2.2.1", 116 | "bson": "^1.1.4", 117 | "denque": "^1.4.1", 118 | "optional-require": "^1.1.8", 119 | "safe-buffer": "^5.1.2" 120 | }, 121 | "engines": { 122 | "node": ">=4" 123 | }, 124 | "optionalDependencies": { 125 | "saslprep": "^1.0.0" 126 | }, 127 | "peerDependenciesMeta": { 128 | "aws4": { 129 | "optional": true 130 | }, 131 | "bson-ext": { 132 | "optional": true 133 | }, 134 | "kerberos": { 135 | "optional": true 136 | }, 137 | "mongodb-client-encryption": { 138 | "optional": true 139 | }, 140 | "mongodb-extjson": { 141 | "optional": true 142 | }, 143 | "snappy": { 144 | "optional": true 145 | } 146 | } 147 | }, 148 | "node_modules/mongodb/node_modules/optional-require": { 149 | "version": "1.1.8", 150 | "resolved": "https://registry.npmjs.org/optional-require/-/optional-require-1.1.8.tgz", 151 | "integrity": "sha512-jq83qaUb0wNg9Krv1c5OQ+58EK+vHde6aBPzLvPPqJm89UQWsvSuFy9X/OSNJnFeSOKo7btE0n8Nl2+nE+z5nA==", 152 | "dependencies": { 153 | "require-at": "^1.0.6" 154 | }, 155 | "engines": { 156 | "node": ">=4" 157 | } 158 | }, 159 | "node_modules/mongoose": { 160 | "version": "5.13.20", 161 | "resolved": "https://registry.npmjs.org/mongoose/-/mongoose-5.13.20.tgz", 162 | "integrity": "sha512-TjGFa/XnJYt+wLmn8y9ssjyO2OhBMeEBtOHb9iJM16EWu2Du6L1Q6zSiEK2ziyYQM8agb4tumNIQFzqbxId7MA==", 163 | "dependencies": { 164 | "@types/bson": "1.x || 4.0.x", 165 | "@types/mongodb": "^3.5.27", 166 | "bson": "^1.1.4", 167 | "kareem": "2.3.2", 168 | "mongodb": "3.7.4", 169 | "mongoose-legacy-pluralize": "1.0.2", 170 | "mpath": "0.8.4", 171 | "mquery": "3.2.5", 172 | "ms": "2.1.2", 173 | "optional-require": "1.0.x", 174 | "regexp-clone": "1.0.0", 175 | "safe-buffer": "5.2.1", 176 | "sift": "13.5.2", 177 | "sliced": "1.0.1" 178 | }, 179 | "engines": { 180 | "node": ">=4.0.0" 181 | }, 182 | "funding": { 183 | "type": "opencollective", 184 | "url": "https://opencollective.com/mongoose" 185 | } 186 | }, 187 | "node_modules/mongoose-execution-time": { 188 | "version": "1.1.0", 189 | "resolved": "https://registry.npmjs.org/mongoose-execution-time/-/mongoose-execution-time-1.1.0.tgz", 190 | "integrity": "sha512-hRYiapuuaIWoq2tA9FfKSbrUuWXEMTBixeFbdSqgIbZb227PLfmOIlyt27Tlbz5CD+F3DJBvHrnElYtKI2z2CQ==" 191 | }, 192 | "node_modules/mongoose-legacy-pluralize": { 193 | "version": "1.0.2", 194 | "resolved": "https://registry.npmjs.org/mongoose-legacy-pluralize/-/mongoose-legacy-pluralize-1.0.2.tgz", 195 | "integrity": "sha512-Yo/7qQU4/EyIS8YDFSeenIvXxZN+ld7YdV9LqFVQJzTLye8unujAWPZ4NWKfFA+RNjh+wvTWKY9Z3E5XM6ZZiQ==", 196 | "peerDependencies": { 197 | "mongoose": "*" 198 | } 199 | }, 200 | "node_modules/mpath": { 201 | "version": "0.8.4", 202 | "resolved": "https://registry.npmjs.org/mpath/-/mpath-0.8.4.tgz", 203 | "integrity": "sha512-DTxNZomBcTWlrMW76jy1wvV37X/cNNxPW1y2Jzd4DZkAaC5ZGsm8bfGfNOthcDuRJujXLqiuS6o3Tpy0JEoh7g==", 204 | "engines": { 205 | "node": ">=4.0.0" 206 | } 207 | }, 208 | "node_modules/mquery": { 209 | "version": "3.2.5", 210 | "resolved": "https://registry.npmjs.org/mquery/-/mquery-3.2.5.tgz", 211 | "integrity": "sha512-VjOKHHgU84wij7IUoZzFRU07IAxd5kWJaDmyUzQlbjHjyoeK5TNeeo8ZsFDtTYnSgpW6n/nMNIHvE3u8Lbrf4A==", 212 | "dependencies": { 213 | "bluebird": "3.5.1", 214 | "debug": "3.1.0", 215 | "regexp-clone": "^1.0.0", 216 | "safe-buffer": "5.1.2", 217 | "sliced": "1.0.1" 218 | }, 219 | "engines": { 220 | "node": ">=4.0.0" 221 | } 222 | }, 223 | "node_modules/mquery/node_modules/safe-buffer": { 224 | "version": "5.1.2", 225 | "resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.1.2.tgz", 226 | "integrity": "sha512-Gd2UZBJDkXlY7GbJxfsE8/nvKkUEU1G38c1siN6QP6a9PT9MmHB8GnpscSmMJSoF8LOIrt8ud/wPtojys4G6+g==" 227 | }, 228 | "node_modules/ms": { 229 | "version": "2.1.2", 230 | "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.2.tgz", 231 | "integrity": "sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w==" 232 | }, 233 | "node_modules/optional-require": { 234 | "version": "1.0.3", 235 | "resolved": "https://registry.npmjs.org/optional-require/-/optional-require-1.0.3.tgz", 236 | "integrity": "sha512-RV2Zp2MY2aeYK5G+B/Sps8lW5NHAzE5QClbFP15j+PWmP+T9PxlJXBOOLoSAdgwFvS4t0aMR4vpedMkbHfh0nA==", 237 | "engines": { 238 | "node": ">=4" 239 | } 240 | }, 241 | "node_modules/process-nextick-args": { 242 | "version": "2.0.1", 243 | "resolved": "https://registry.npmjs.org/process-nextick-args/-/process-nextick-args-2.0.1.tgz", 244 | "integrity": "sha512-3ouUOpQhtgrbOa17J7+uxOTpITYWaGP7/AhoR3+A+/1e9skrzelGi/dXzEYyvbxubEF6Wn2ypscTKiKJFFn1ag==" 245 | }, 246 | "node_modules/readable-stream": { 247 | "version": "2.3.8", 248 | "resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-2.3.8.tgz", 249 | "integrity": "sha512-8p0AUk4XODgIewSi0l8Epjs+EVnWiK7NoDIEGU0HhE7+ZyY8D1IMY7odu5lRrFXGg71L15KG8QrPmum45RTtdA==", 250 | "dependencies": { 251 | "core-util-is": "~1.0.0", 252 | "inherits": "~2.0.3", 253 | "isarray": "~1.0.0", 254 | "process-nextick-args": "~2.0.0", 255 | "safe-buffer": "~5.1.1", 256 | "string_decoder": "~1.1.1", 257 | "util-deprecate": "~1.0.1" 258 | } 259 | }, 260 | "node_modules/readable-stream/node_modules/safe-buffer": { 261 | "version": "5.1.2", 262 | "resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.1.2.tgz", 263 | "integrity": "sha512-Gd2UZBJDkXlY7GbJxfsE8/nvKkUEU1G38c1siN6QP6a9PT9MmHB8GnpscSmMJSoF8LOIrt8ud/wPtojys4G6+g==" 264 | }, 265 | "node_modules/regexp-clone": { 266 | "version": "1.0.0", 267 | "resolved": "https://registry.npmjs.org/regexp-clone/-/regexp-clone-1.0.0.tgz", 268 | "integrity": "sha512-TuAasHQNamyyJ2hb97IuBEif4qBHGjPHBS64sZwytpLEqtBQ1gPJTnOaQ6qmpET16cK14kkjbazl6+p0RRv0yw==" 269 | }, 270 | "node_modules/require-at": { 271 | "version": "1.0.6", 272 | "resolved": "https://registry.npmjs.org/require-at/-/require-at-1.0.6.tgz", 273 | "integrity": "sha512-7i1auJbMUrXEAZCOQ0VNJgmcT2VOKPRl2YGJwgpHpC9CE91Mv4/4UYIUm4chGJaI381ZDq1JUicFii64Hapd8g==", 274 | "engines": { 275 | "node": ">=4" 276 | } 277 | }, 278 | "node_modules/safe-buffer": { 279 | "version": "5.2.1", 280 | "resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.2.1.tgz", 281 | "integrity": "sha512-rp3So07KcdmmKbGvgaNxQSJr7bGVSVk5S9Eq1F+ppbRo70+YeaDxkw5Dd8NPN+GD6bjnYm2VuPuCXmpuYvmCXQ==", 282 | "funding": [ 283 | { 284 | "type": "github", 285 | "url": "https://github.com/sponsors/feross" 286 | }, 287 | { 288 | "type": "patreon", 289 | "url": "https://www.patreon.com/feross" 290 | }, 291 | { 292 | "type": "consulting", 293 | "url": "https://feross.org/support" 294 | } 295 | ] 296 | }, 297 | "node_modules/saslprep": { 298 | "version": "1.0.3", 299 | "resolved": "https://registry.npmjs.org/saslprep/-/saslprep-1.0.3.tgz", 300 | "integrity": "sha512-/MY/PEMbk2SuY5sScONwhUDsV2p77Znkb/q3nSVstq/yQzYJOH/Azh29p9oJLsl3LnQwSvZDKagDGBsBwSooag==", 301 | "optional": true, 302 | "dependencies": { 303 | "sparse-bitfield": "^3.0.3" 304 | }, 305 | "engines": { 306 | "node": ">=6" 307 | } 308 | }, 309 | "node_modules/sift": { 310 | "version": "13.5.2", 311 | "resolved": "https://registry.npmjs.org/sift/-/sift-13.5.2.tgz", 312 | "integrity": "sha512-+gxdEOMA2J+AI+fVsCqeNn7Tgx3M9ZN9jdi95939l1IJ8cZsqS8sqpJyOkic2SJk+1+98Uwryt/gL6XDaV+UZA==" 313 | }, 314 | "node_modules/sliced": { 315 | "version": "1.0.1", 316 | "resolved": "https://registry.npmjs.org/sliced/-/sliced-1.0.1.tgz", 317 | "integrity": "sha512-VZBmZP8WU3sMOZm1bdgTadsQbcscK0UM8oKxKVBs4XAhUo2Xxzm/OFMGBkPusxw9xL3Uy8LrzEqGqJhclsr0yA==" 318 | }, 319 | "node_modules/sparse-bitfield": { 320 | "version": "3.0.3", 321 | "resolved": "https://registry.npmjs.org/sparse-bitfield/-/sparse-bitfield-3.0.3.tgz", 322 | "integrity": "sha512-kvzhi7vqKTfkh0PZU+2D2PIllw2ymqJKujUcyPMd9Y75Nv4nPbGJZXNhxsgdQab2BmlDct1YnfQCguEvHr7VsQ==", 323 | "optional": true, 324 | "dependencies": { 325 | "memory-pager": "^1.0.2" 326 | } 327 | }, 328 | "node_modules/string_decoder": { 329 | "version": "1.1.1", 330 | "resolved": "https://registry.npmjs.org/string_decoder/-/string_decoder-1.1.1.tgz", 331 | "integrity": "sha512-n/ShnvDi6FHbbVfviro+WojiFzv+s8MPMHBczVePfUpDJLwoLT0ht1l4YwBCbi8pJAveEEdnkHyPyTP/mzRfwg==", 332 | "dependencies": { 333 | "safe-buffer": "~5.1.0" 334 | } 335 | }, 336 | "node_modules/string_decoder/node_modules/safe-buffer": { 337 | "version": "5.1.2", 338 | "resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.1.2.tgz", 339 | "integrity": "sha512-Gd2UZBJDkXlY7GbJxfsE8/nvKkUEU1G38c1siN6QP6a9PT9MmHB8GnpscSmMJSoF8LOIrt8ud/wPtojys4G6+g==" 340 | }, 341 | "node_modules/util-deprecate": { 342 | "version": "1.0.2", 343 | "resolved": "https://registry.npmjs.org/util-deprecate/-/util-deprecate-1.0.2.tgz", 344 | "integrity": "sha512-EPD5q1uXyFxJpCrLnCc1nHnq3gOa6DZBocAIiI2TaSCA7VCJ1UJDMagCzIkXNsUYfD1daK//LTEQ8xiIbrHtcw==" 345 | } 346 | }, 347 | "dependencies": { 348 | "@types/bson": { 349 | "version": "4.0.5", 350 | "resolved": "https://registry.npmjs.org/@types/bson/-/bson-4.0.5.tgz", 351 | "integrity": "sha512-vVLwMUqhYJSQ/WKcE60eFqcyuWse5fGH+NMAXHuKrUAPoryq3ATxk5o4bgYNtg5aOM4APVg7Hnb3ASqUYG0PKg==", 352 | "requires": { 353 | "@types/node": "*" 354 | } 355 | }, 356 | "@types/mongodb": { 357 | "version": "3.6.20", 358 | "resolved": "https://registry.npmjs.org/@types/mongodb/-/mongodb-3.6.20.tgz", 359 | "integrity": "sha512-WcdpPJCakFzcWWD9juKoZbRtQxKIMYF/JIAM4JrNHrMcnJL6/a2NWjXxW7fo9hxboxxkg+icff8d7+WIEvKgYQ==", 360 | "requires": { 361 | "@types/bson": "*", 362 | "@types/node": "*" 363 | } 364 | }, 365 | "@types/node": { 366 | "version": "20.4.2", 367 | "resolved": "https://registry.npmjs.org/@types/node/-/node-20.4.2.tgz", 368 | "integrity": "sha512-Dd0BYtWgnWJKwO1jkmTrzofjK2QXXcai0dmtzvIBhcA+RsG5h8R3xlyta0kGOZRNfL9GuRtb1knmPEhQrePCEw==" 369 | }, 370 | "bl": { 371 | "version": "2.2.1", 372 | "resolved": "https://registry.npmjs.org/bl/-/bl-2.2.1.tgz", 373 | "integrity": "sha512-6Pesp1w0DEX1N550i/uGV/TqucVL4AM/pgThFSN/Qq9si1/DF9aIHs1BxD8V/QU0HoeHO6cQRTAuYnLPKq1e4g==", 374 | "requires": { 375 | "readable-stream": "^2.3.5", 376 | "safe-buffer": "^5.1.1" 377 | } 378 | }, 379 | "bluebird": { 380 | "version": "3.5.1", 381 | "resolved": "https://registry.npmjs.org/bluebird/-/bluebird-3.5.1.tgz", 382 | "integrity": "sha512-MKiLiV+I1AA596t9w1sQJ8jkiSr5+ZKi0WKrYGUn6d1Fx+Ij4tIj+m2WMQSGczs5jZVxV339chE8iwk6F64wjA==" 383 | }, 384 | "bson": { 385 | "version": "1.1.6", 386 | "resolved": "https://registry.npmjs.org/bson/-/bson-1.1.6.tgz", 387 | "integrity": "sha512-EvVNVeGo4tHxwi8L6bPj3y3itEvStdwvvlojVxxbyYfoaxJ6keLgrTuKdyfEAszFK+H3olzBuafE0yoh0D1gdg==" 388 | }, 389 | "core-util-is": { 390 | "version": "1.0.3", 391 | "resolved": "https://registry.npmjs.org/core-util-is/-/core-util-is-1.0.3.tgz", 392 | "integrity": "sha512-ZQBvi1DcpJ4GDqanjucZ2Hj3wEO5pZDS89BWbkcrvdxksJorwUDDZamX9ldFkp9aw2lmBDLgkObEA4DWNJ9FYQ==" 393 | }, 394 | "debug": { 395 | "version": "3.1.0", 396 | "resolved": "https://registry.npmjs.org/debug/-/debug-3.1.0.tgz", 397 | "integrity": "sha512-OX8XqP7/1a9cqkxYw2yXss15f26NKWBpDXQd0/uK/KPqdQhxbPa994hnzjcE2VqQpDslf55723cKPUOGSmMY3g==", 398 | "requires": { 399 | "ms": "2.0.0" 400 | }, 401 | "dependencies": { 402 | "ms": { 403 | "version": "2.0.0", 404 | "resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz", 405 | "integrity": "sha512-Tpp60P6IUJDTuOq/5Z8cdskzJujfwqfOTkrwIwj7IRISpnkJnT6SyJ4PCPnGMoFjC9ddhal5KVIYtAt97ix05A==" 406 | } 407 | } 408 | }, 409 | "denque": { 410 | "version": "1.5.1", 411 | "resolved": "https://registry.npmjs.org/denque/-/denque-1.5.1.tgz", 412 | "integrity": "sha512-XwE+iZ4D6ZUB7mfYRMb5wByE8L74HCn30FBN7sWnXksWc1LO1bPDl67pBR9o/kC4z/xSNAwkMYcGgqDV3BE3Hw==" 413 | }, 414 | "inherits": { 415 | "version": "2.0.4", 416 | "resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.4.tgz", 417 | "integrity": "sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ==" 418 | }, 419 | "isarray": { 420 | "version": "1.0.0", 421 | "resolved": "https://registry.npmjs.org/isarray/-/isarray-1.0.0.tgz", 422 | "integrity": "sha512-VLghIWNM6ELQzo7zwmcg0NmTVyWKYjvIeM83yjp0wRDTmUnrM678fQbcKBo6n2CJEF0szoG//ytg+TKla89ALQ==" 423 | }, 424 | "kareem": { 425 | "version": "2.3.2", 426 | "resolved": "https://registry.npmjs.org/kareem/-/kareem-2.3.2.tgz", 427 | "integrity": "sha512-STHz9P7X2L4Kwn72fA4rGyqyXdmrMSdxqHx9IXon/FXluXieaFA6KJ2upcHAHxQPQ0LeM/OjLrhFxifHewOALQ==" 428 | }, 429 | "memory-pager": { 430 | "version": "1.5.0", 431 | "resolved": "https://registry.npmjs.org/memory-pager/-/memory-pager-1.5.0.tgz", 432 | "integrity": "sha512-ZS4Bp4r/Zoeq6+NLJpP+0Zzm0pR8whtGPf1XExKLJBAczGMnSi3It14OiNCStjQjM6NU1okjQGSxgEZN8eBYKg==", 433 | "optional": true 434 | }, 435 | "mongodb": { 436 | "version": "3.7.4", 437 | "resolved": "https://registry.npmjs.org/mongodb/-/mongodb-3.7.4.tgz", 438 | "integrity": "sha512-K5q8aBqEXMwWdVNh94UQTwZ6BejVbFhh1uB6c5FKtPE9eUMZPUO3sRZdgIEcHSrAWmxzpG/FeODDKL388sqRmw==", 439 | "requires": { 440 | "bl": "^2.2.1", 441 | "bson": "^1.1.4", 442 | "denque": "^1.4.1", 443 | "optional-require": "^1.1.8", 444 | "safe-buffer": "^5.1.2", 445 | "saslprep": "^1.0.0" 446 | }, 447 | "dependencies": { 448 | "optional-require": { 449 | "version": "1.1.8", 450 | "resolved": "https://registry.npmjs.org/optional-require/-/optional-require-1.1.8.tgz", 451 | "integrity": "sha512-jq83qaUb0wNg9Krv1c5OQ+58EK+vHde6aBPzLvPPqJm89UQWsvSuFy9X/OSNJnFeSOKo7btE0n8Nl2+nE+z5nA==", 452 | "requires": { 453 | "require-at": "^1.0.6" 454 | } 455 | } 456 | } 457 | }, 458 | "mongoose": { 459 | "version": "5.13.20", 460 | "resolved": "https://registry.npmjs.org/mongoose/-/mongoose-5.13.20.tgz", 461 | "integrity": "sha512-TjGFa/XnJYt+wLmn8y9ssjyO2OhBMeEBtOHb9iJM16EWu2Du6L1Q6zSiEK2ziyYQM8agb4tumNIQFzqbxId7MA==", 462 | "requires": { 463 | "@types/bson": "1.x || 4.0.x", 464 | "@types/mongodb": "^3.5.27", 465 | "bson": "^1.1.4", 466 | "kareem": "2.3.2", 467 | "mongodb": "3.7.4", 468 | "mongoose-legacy-pluralize": "1.0.2", 469 | "mpath": "0.8.4", 470 | "mquery": "3.2.5", 471 | "ms": "2.1.2", 472 | "optional-require": "1.0.x", 473 | "regexp-clone": "1.0.0", 474 | "safe-buffer": "5.2.1", 475 | "sift": "13.5.2", 476 | "sliced": "1.0.1" 477 | } 478 | }, 479 | "mongoose-execution-time": { 480 | "version": "1.1.0", 481 | "resolved": "https://registry.npmjs.org/mongoose-execution-time/-/mongoose-execution-time-1.1.0.tgz", 482 | "integrity": "sha512-hRYiapuuaIWoq2tA9FfKSbrUuWXEMTBixeFbdSqgIbZb227PLfmOIlyt27Tlbz5CD+F3DJBvHrnElYtKI2z2CQ==" 483 | }, 484 | "mongoose-legacy-pluralize": { 485 | "version": "1.0.2", 486 | "resolved": "https://registry.npmjs.org/mongoose-legacy-pluralize/-/mongoose-legacy-pluralize-1.0.2.tgz", 487 | "integrity": "sha512-Yo/7qQU4/EyIS8YDFSeenIvXxZN+ld7YdV9LqFVQJzTLye8unujAWPZ4NWKfFA+RNjh+wvTWKY9Z3E5XM6ZZiQ==", 488 | "requires": {} 489 | }, 490 | "mpath": { 491 | "version": "0.8.4", 492 | "resolved": "https://registry.npmjs.org/mpath/-/mpath-0.8.4.tgz", 493 | "integrity": "sha512-DTxNZomBcTWlrMW76jy1wvV37X/cNNxPW1y2Jzd4DZkAaC5ZGsm8bfGfNOthcDuRJujXLqiuS6o3Tpy0JEoh7g==" 494 | }, 495 | "mquery": { 496 | "version": "3.2.5", 497 | "resolved": "https://registry.npmjs.org/mquery/-/mquery-3.2.5.tgz", 498 | "integrity": "sha512-VjOKHHgU84wij7IUoZzFRU07IAxd5kWJaDmyUzQlbjHjyoeK5TNeeo8ZsFDtTYnSgpW6n/nMNIHvE3u8Lbrf4A==", 499 | "requires": { 500 | "bluebird": "3.5.1", 501 | "debug": "3.1.0", 502 | "regexp-clone": "^1.0.0", 503 | "safe-buffer": "5.1.2", 504 | "sliced": "1.0.1" 505 | }, 506 | "dependencies": { 507 | "safe-buffer": { 508 | "version": "5.1.2", 509 | "resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.1.2.tgz", 510 | "integrity": "sha512-Gd2UZBJDkXlY7GbJxfsE8/nvKkUEU1G38c1siN6QP6a9PT9MmHB8GnpscSmMJSoF8LOIrt8ud/wPtojys4G6+g==" 511 | } 512 | } 513 | }, 514 | "ms": { 515 | "version": "2.1.2", 516 | "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.2.tgz", 517 | "integrity": "sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w==" 518 | }, 519 | "optional-require": { 520 | "version": "1.0.3", 521 | "resolved": "https://registry.npmjs.org/optional-require/-/optional-require-1.0.3.tgz", 522 | "integrity": "sha512-RV2Zp2MY2aeYK5G+B/Sps8lW5NHAzE5QClbFP15j+PWmP+T9PxlJXBOOLoSAdgwFvS4t0aMR4vpedMkbHfh0nA==" 523 | }, 524 | "process-nextick-args": { 525 | "version": "2.0.1", 526 | "resolved": "https://registry.npmjs.org/process-nextick-args/-/process-nextick-args-2.0.1.tgz", 527 | "integrity": "sha512-3ouUOpQhtgrbOa17J7+uxOTpITYWaGP7/AhoR3+A+/1e9skrzelGi/dXzEYyvbxubEF6Wn2ypscTKiKJFFn1ag==" 528 | }, 529 | "readable-stream": { 530 | "version": "2.3.8", 531 | "resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-2.3.8.tgz", 532 | "integrity": "sha512-8p0AUk4XODgIewSi0l8Epjs+EVnWiK7NoDIEGU0HhE7+ZyY8D1IMY7odu5lRrFXGg71L15KG8QrPmum45RTtdA==", 533 | "requires": { 534 | "core-util-is": "~1.0.0", 535 | "inherits": "~2.0.3", 536 | "isarray": "~1.0.0", 537 | "process-nextick-args": "~2.0.0", 538 | "safe-buffer": "~5.1.1", 539 | "string_decoder": "~1.1.1", 540 | "util-deprecate": "~1.0.1" 541 | }, 542 | "dependencies": { 543 | "safe-buffer": { 544 | "version": "5.1.2", 545 | "resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.1.2.tgz", 546 | "integrity": "sha512-Gd2UZBJDkXlY7GbJxfsE8/nvKkUEU1G38c1siN6QP6a9PT9MmHB8GnpscSmMJSoF8LOIrt8ud/wPtojys4G6+g==" 547 | } 548 | } 549 | }, 550 | "regexp-clone": { 551 | "version": "1.0.0", 552 | "resolved": "https://registry.npmjs.org/regexp-clone/-/regexp-clone-1.0.0.tgz", 553 | "integrity": "sha512-TuAasHQNamyyJ2hb97IuBEif4qBHGjPHBS64sZwytpLEqtBQ1gPJTnOaQ6qmpET16cK14kkjbazl6+p0RRv0yw==" 554 | }, 555 | "require-at": { 556 | "version": "1.0.6", 557 | "resolved": "https://registry.npmjs.org/require-at/-/require-at-1.0.6.tgz", 558 | "integrity": "sha512-7i1auJbMUrXEAZCOQ0VNJgmcT2VOKPRl2YGJwgpHpC9CE91Mv4/4UYIUm4chGJaI381ZDq1JUicFii64Hapd8g==" 559 | }, 560 | "safe-buffer": { 561 | "version": "5.2.1", 562 | "resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.2.1.tgz", 563 | "integrity": "sha512-rp3So07KcdmmKbGvgaNxQSJr7bGVSVk5S9Eq1F+ppbRo70+YeaDxkw5Dd8NPN+GD6bjnYm2VuPuCXmpuYvmCXQ==" 564 | }, 565 | "saslprep": { 566 | "version": "1.0.3", 567 | "resolved": "https://registry.npmjs.org/saslprep/-/saslprep-1.0.3.tgz", 568 | "integrity": "sha512-/MY/PEMbk2SuY5sScONwhUDsV2p77Znkb/q3nSVstq/yQzYJOH/Azh29p9oJLsl3LnQwSvZDKagDGBsBwSooag==", 569 | "optional": true, 570 | "requires": { 571 | "sparse-bitfield": "^3.0.3" 572 | } 573 | }, 574 | "sift": { 575 | "version": "13.5.2", 576 | "resolved": "https://registry.npmjs.org/sift/-/sift-13.5.2.tgz", 577 | "integrity": "sha512-+gxdEOMA2J+AI+fVsCqeNn7Tgx3M9ZN9jdi95939l1IJ8cZsqS8sqpJyOkic2SJk+1+98Uwryt/gL6XDaV+UZA==" 578 | }, 579 | "sliced": { 580 | "version": "1.0.1", 581 | "resolved": "https://registry.npmjs.org/sliced/-/sliced-1.0.1.tgz", 582 | "integrity": "sha512-VZBmZP8WU3sMOZm1bdgTadsQbcscK0UM8oKxKVBs4XAhUo2Xxzm/OFMGBkPusxw9xL3Uy8LrzEqGqJhclsr0yA==" 583 | }, 584 | "sparse-bitfield": { 585 | "version": "3.0.3", 586 | "resolved": "https://registry.npmjs.org/sparse-bitfield/-/sparse-bitfield-3.0.3.tgz", 587 | "integrity": "sha512-kvzhi7vqKTfkh0PZU+2D2PIllw2ymqJKujUcyPMd9Y75Nv4nPbGJZXNhxsgdQab2BmlDct1YnfQCguEvHr7VsQ==", 588 | "optional": true, 589 | "requires": { 590 | "memory-pager": "^1.0.2" 591 | } 592 | }, 593 | "string_decoder": { 594 | "version": "1.1.1", 595 | "resolved": "https://registry.npmjs.org/string_decoder/-/string_decoder-1.1.1.tgz", 596 | "integrity": "sha512-n/ShnvDi6FHbbVfviro+WojiFzv+s8MPMHBczVePfUpDJLwoLT0ht1l4YwBCbi8pJAveEEdnkHyPyTP/mzRfwg==", 597 | "requires": { 598 | "safe-buffer": "~5.1.0" 599 | }, 600 | "dependencies": { 601 | "safe-buffer": { 602 | "version": "5.1.2", 603 | "resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.1.2.tgz", 604 | "integrity": "sha512-Gd2UZBJDkXlY7GbJxfsE8/nvKkUEU1G38c1siN6QP6a9PT9MmHB8GnpscSmMJSoF8LOIrt8ud/wPtojys4G6+g==" 605 | } 606 | } 607 | }, 608 | "util-deprecate": { 609 | "version": "1.0.2", 610 | "resolved": "https://registry.npmjs.org/util-deprecate/-/util-deprecate-1.0.2.tgz", 611 | "integrity": "sha512-EPD5q1uXyFxJpCrLnCc1nHnq3gOa6DZBocAIiI2TaSCA7VCJ1UJDMagCzIkXNsUYfD1daK//LTEQ8xiIbrHtcw==" 612 | } 613 | } 614 | } 615 | -------------------------------------------------------------------------------- /example/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "mongoose-execution-time-example", 3 | "version": "1.0.0", 4 | "description": "Mongoose execution time plugin example", 5 | "main": "app.js", 6 | "scripts": { 7 | "start": "node app.js" 8 | }, 9 | "keywords": [], 10 | "author": "Hamza", 11 | "license": "ISC", 12 | "dependencies": { 13 | "mongoose": "^5.9.20", 14 | "mongoose-execution-time": "1.1.0" 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /index.ts: -------------------------------------------------------------------------------- 1 | export interface LogExecutionTimeConfig { 2 | logger?: any; 3 | loggerLevel?: string; 4 | loggerVerbosity?: LoggerVerbosity, 5 | loggerFunction?: LoggerFunction 6 | } 7 | 8 | export enum LoggerVerbosity { 9 | Normal, 10 | High 11 | } 12 | 13 | type LoggerFunction = ( 14 | operation: string, 15 | collectionName: string, 16 | executionTimeMS: number, 17 | filter: Object | null, 18 | update: Object | null, 19 | additionalLogProperties: any, 20 | aggregationPipeline?: Array | null | undefined, 21 | ) => void; 22 | 23 | 24 | let logger : any = console; 25 | let loggerLevel: string = 'debug'; 26 | let loggerVerbosity : LoggerVerbosity = LoggerVerbosity.High; 27 | let loggerFunction : LoggerFunction = defaultLoggingFunction; 28 | 29 | export function logExecutionTime (targetSchema : any, config ?: LogExecutionTimeConfig) { 30 | 31 | targetSchema.query.additionalLogProperties = function(additionalProperties: Object | string | number | boolean) { 32 | this.__additionalProperties = additionalProperties; 33 | return this; 34 | }; 35 | 36 | if(!config) { 37 | config = {} as LogExecutionTimeConfig; 38 | } 39 | if(config.logger) { 40 | logger = config.logger; 41 | } 42 | if(config.loggerLevel) { 43 | loggerLevel = config.loggerLevel; 44 | } 45 | if(config.loggerVerbosity != null) { 46 | loggerVerbosity = config.loggerVerbosity; 47 | } 48 | 49 | if(config.loggerFunction) { 50 | loggerFunction = config.loggerFunction; 51 | } 52 | 53 | const targetMethods = [ 54 | 'find', 55 | 'findOne', 56 | 'count', 57 | 'countDocuments', 58 | 'estimatedDocumentCount', 59 | 'findOneAndUpdate', 60 | 'findOneAndRemove', 61 | 'findOneAndDelete', 62 | 'deleteOne', 63 | 'deleteMany', 64 | 'remove', 65 | 'aggregate', 66 | ] 67 | 68 | targetMethods.forEach( method => { 69 | targetSchema.pre(method, preQueryHook); 70 | targetSchema.post(method, postQueryHook); 71 | }) 72 | } 73 | 74 | function preQueryHook() { 75 | // @ts-ignore 76 | this.__startTime = Date.now(); 77 | } 78 | function postQueryHook() { 79 | 80 | // @ts-ignore 81 | const target = this; 82 | 83 | if (target.__startTime != null) { 84 | 85 | const op = target.constructor.name === 'Aggregate' ? 'aggregate' : target.op; 86 | const collectionName = target._collection ? target._collection.collectionName : target._model.collection.collectionName; 87 | 88 | loggerFunction( 89 | op, 90 | collectionName, 91 | Date.now() - target.__startTime, 92 | target._conditions, 93 | target._update, 94 | target.__additionalProperties, 95 | target._pipeline 96 | ) 97 | } 98 | } 99 | function defaultLoggingFunction( 100 | operation: string, 101 | collectionName: string, 102 | executionTimeMS: number, 103 | filter: Object | null, 104 | update: Object | null, 105 | additionalLogProperties: any, 106 | aggregationPipeline: Array | null | undefined) { 107 | 108 | let logProperties: any = null; 109 | 110 | if(loggerVerbosity == LoggerVerbosity.High) { 111 | 112 | logProperties = {} 113 | 114 | if(filter) { 115 | logProperties.filter = filter 116 | } 117 | 118 | if(update) { 119 | logProperties.update = update 120 | } 121 | 122 | if(aggregationPipeline) { 123 | logProperties.aggregationPipeline = JSON.stringify(aggregationPipeline) 124 | } 125 | } 126 | 127 | if(additionalLogProperties) { 128 | logProperties = logProperties 129 | ? { ...logProperties, additionalLogProperties } 130 | : { additionalLogProperties } 131 | } 132 | 133 | logger[loggerLevel](`Query: ${operation} in ${collectionName} completed in: ${executionTimeMS} ms`, logProperties) 134 | } 135 | 136 | 137 | 138 | 139 | -------------------------------------------------------------------------------- /package-lock.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "mongoose-execution-time", 3 | "version": "1.1.1", 4 | "lockfileVersion": 2, 5 | "requires": true, 6 | "packages": { 7 | "": { 8 | "version": "1.1.1", 9 | "license": "MIT", 10 | "devDependencies": { 11 | "typescript": "^5.1.6" 12 | } 13 | }, 14 | "node_modules/typescript": { 15 | "version": "5.1.6", 16 | "resolved": "https://registry.npmjs.org/typescript/-/typescript-5.1.6.tgz", 17 | "integrity": "sha512-zaWCozRZ6DLEWAWFrVDz1H6FVXzUSfTy5FUMWsQlU8Ym5JP9eO4xkTIROFCQvhQf61z6O/G6ugw3SgAnvvm+HA==", 18 | "dev": true, 19 | "bin": { 20 | "tsc": "bin/tsc", 21 | "tsserver": "bin/tsserver" 22 | }, 23 | "engines": { 24 | "node": ">=14.17" 25 | } 26 | } 27 | }, 28 | "dependencies": { 29 | "typescript": { 30 | "version": "5.1.6", 31 | "resolved": "https://registry.npmjs.org/typescript/-/typescript-5.1.6.tgz", 32 | "integrity": "sha512-zaWCozRZ6DLEWAWFrVDz1H6FVXzUSfTy5FUMWsQlU8Ym5JP9eO4xkTIROFCQvhQf61z6O/G6ugw3SgAnvvm+HA==", 33 | "dev": true 34 | } 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "mongoose-execution-time", 3 | "version": "1.1.1", 4 | "description": "Mongoose plugin for measuring and logging query execution time", 5 | "main": "dist/index.js", 6 | "scripts": { 7 | "build": "tsc", 8 | "prepare": "tsc" 9 | }, 10 | "keywords": [ 11 | "mongoose", 12 | "mongodb", 13 | "database", 14 | "query execution time", 15 | "logging", 16 | "query time" 17 | ], 18 | "author": "Hamza Sabljakovic ", 19 | "license": "MIT", 20 | "devDependencies": { 21 | "typescript": "^5.1.6" 22 | }, 23 | "repository": { 24 | "url": "https://github.com/sabljakovich/mongoose-execution-time/" 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | /* Visit https://aka.ms/tsconfig.json to read more about this file */ 4 | 5 | /* Basic Options */ 6 | // "incremental": true, /* Enable incremental compilation */ 7 | "target": "es5", /* Specify ECMAScript target version: 'ES3' (default), 'ES5', 'ES2015', 'ES2016', 'ES2017', 'ES2018', 'ES2019', 'ES2020', or 'ESNEXT'. */ 8 | "module": "commonjs", /* Specify module code generation: 'none', 'commonjs', 'amd', 'system', 'umd', 'es2015', 'es2020', or 'ESNext'. */ 9 | // "lib": [], /* Specify library files to be included in the compilation. */ 10 | // "allowJs": true, /* Allow javascript files to be compiled. */ 11 | // "checkJs": true, /* Report errors in .js files. */ 12 | // "jsx": "preserve", /* Specify JSX code generation: 'preserve', 'react-native', or 'react'. */ 13 | // "declaration": true, /* Generates corresponding '.d.ts' file. */ 14 | // "declarationMap": true, /* Generates a sourcemap for each corresponding '.d.ts' file. */ 15 | // "sourceMap": true, /* Generates corresponding '.map' file. */ 16 | // "outFile": "./", /* Concatenate and emit output to single file. */ 17 | "outDir": "./dist", /* Redirect output structure to the directory. */ 18 | // "rootDir": "./", /* Specify the root directory of input files. Use to control the output directory structure with --outDir. */ 19 | // "composite": true, /* Enable project compilation */ 20 | // "tsBuildInfoFile": "./", /* Specify file to store incremental compilation information */ 21 | // "removeComments": true, /* Do not emit comments to output. */ 22 | // "noEmit": true, /* Do not emit outputs. */ 23 | // "importHelpers": true, /* Import emit helpers from 'tslib'. */ 24 | // "downlevelIteration": true, /* Provide full support for iterables in 'for-of', spread, and destructuring when targeting 'ES5' or 'ES3'. */ 25 | // "isolatedModules": true, /* Transpile each file as a separate module (similar to 'ts.transpileModule'). */ 26 | 27 | /* Strict Type-Checking Options */ 28 | "strict": true, /* Enable all strict type-checking options. */ 29 | // "noImplicitAny": true, /* Raise error on expressions and declarations with an implied 'any' type. */ 30 | // "strictNullChecks": true, /* Enable strict null checks. */ 31 | // "strictFunctionTypes": true, /* Enable strict checking of function types. */ 32 | // "strictBindCallApply": true, /* Enable strict 'bind', 'call', and 'apply' methods on functions. */ 33 | // "strictPropertyInitialization": true, /* Enable strict checking of property initialization in classes. */ 34 | // "noImplicitThis": true, /* Raise error on 'this' expressions with an implied 'any' type. */ 35 | // "alwaysStrict": true, /* Parse in strict mode and emit "use strict" for each source file. */ 36 | 37 | /* Additional Checks */ 38 | // "noUnusedLocals": true, /* Report errors on unused locals. */ 39 | // "noUnusedParameters": true, /* Report errors on unused parameters. */ 40 | // "noImplicitReturns": true, /* Report error when not all code paths in function return a value. */ 41 | // "noFallthroughCasesInSwitch": true, /* Report errors for fallthrough cases in switch statement. */ 42 | 43 | /* Module Resolution Options */ 44 | // "moduleResolution": "node", /* Specify module resolution strategy: 'node' (Node.js) or 'classic' (TypeScript pre-1.6). */ 45 | // "baseUrl": "./", /* Base directory to resolve non-absolute module names. */ 46 | // "paths": {}, /* A series of entries which re-map imports to lookup locations relative to the 'baseUrl'. */ 47 | // "rootDirs": [], /* List of root folders whose combined content represents the structure of the project at runtime. */ 48 | // "typeRoots": [], /* List of folders to include type definitions from. */ 49 | // "types": [], /* Type declaration files to be included in compilation. */ 50 | // "allowSyntheticDefaultImports": true, /* Allow default imports from modules with no default export. This does not affect code emit, just typechecking. */ 51 | "esModuleInterop": true, /* Enables emit interoperability between CommonJS and ES Modules via creation of namespace objects for all imports. Implies 'allowSyntheticDefaultImports'. */ 52 | // "preserveSymlinks": true, /* Do not resolve the real path of symlinks. */ 53 | // "allowUmdGlobalAccess": true, /* Allow accessing UMD globals from modules. */ 54 | 55 | /* Source Map Options */ 56 | // "sourceRoot": "", /* Specify the location where debugger should locate TypeScript files instead of source locations. */ 57 | // "mapRoot": "", /* Specify the location where debugger should locate map files instead of generated locations. */ 58 | // "inlineSourceMap": true, /* Emit a single file with source maps instead of having a separate file. */ 59 | // "inlineSources": true, /* Emit the source alongside the sourcemaps within a single file; requires '--inlineSourceMap' or '--sourceMap' to be set. */ 60 | 61 | /* Experimental Options */ 62 | // "experimentalDecorators": true, /* Enables experimental support for ES7 decorators. */ 63 | // "emitDecoratorMetadata": true, /* Enables experimental support for emitting type metadata for decorators. */ 64 | 65 | /* Advanced Options */ 66 | "skipLibCheck": true, /* Skip type checking of declaration files. */ 67 | "forceConsistentCasingInFileNames": true /* Disallow inconsistently-cased references to the same file. */ 68 | } 69 | } 70 | --------------------------------------------------------------------------------