New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

mongo-slow-queries

Package Overview
Dependencies
Maintainers
23
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

mongo-slow-queries - npm Package Compare versions

Comparing version 1.0.1 to 1.0.2

.eslintrc.json

15

package.json
{
"name": "mongo-slow-queries",
"version": "1.0.1",
"version": "1.0.2",
"description": "Utility for identifying slow queries in Mongo",
"main": "src/index.js",
"scripts": {
"test": "jasmine"
"test": "jasmine",
"lint": "eslint ."
},

@@ -26,7 +27,13 @@ "repository": {

"devDependencies": {
"jasmine": "^2.5.3"
"eslint": ">=3",
"eslint-config-mixmax": "^0.6.0",
"jasmine": "^2.5.3",
"pre-commit": "^1.2.2"
},
"dependencies": {
"underscore": "^1.8.3"
}
},
"pre-commit": [
"lint"
]
}

@@ -6,3 +6,3 @@ # mongo-slow-queries

```
$ npm install mongo-slow-queries --save
$ npm install mongo-slow-queries
```

@@ -9,0 +9,0 @@

@@ -35,30 +35,30 @@ var fingerprint = require('../src/fingerprint');

var obj = {
"find": "users",
"filter": {
"$or": [{
"_id": {
"$regex": "(^| |@)foo",
"$options": "i"
'find': 'users',
'filter': {
'$or': [{
'_id': {
'$regex': '(^| |@)foo',
'$options': 'i'
}
}, {
"name": {
"$regex": "(^| |@)bar",
"$options": "i"
'name': {
'$regex': '(^| |@)bar',
'$options': 'i'
}
}, {
"email": {
"$regex": "(^| |@)baz",
"$options": "i"
'email': {
'$regex': '(^| |@)baz',
'$options': 'i'
}
}]
},
"sort": {
"createdAt": -1
'sort': {
'createdAt': -1
},
"projection": {
"_id": 1,
"name": 1,
"email": 1
'projection': {
'_id': 1,
'name': 1,
'email': 1
},
"limit": 10
'limit': 10
};

@@ -65,0 +65,0 @@ expect(fingerprint(obj)).toEqual('{ find, filter: { $or: [ { _id: { $regex, $options } }, { name: { $regex, $options } }, { email: { $regex, $options } } ] }, sort: { createdAt }, projection: { _id, name, email }, limit }');

@@ -32,7 +32,7 @@ var _ = require('underscore');

var keys = _.keys(obj),
fprint = '{ ';
fprint = '{ ';
for (var i = 0; i < keys.length; i++) {
var key = keys[i],
val = obj[key];
val = obj[key];
if (_.isArray(val)) {

@@ -39,0 +39,0 @@ fprint += `${key}: ${arrayFingerprint(val)}`;

@@ -8,5 +8,16 @@ 'use strict';

const VALID_OPTIONS = ['db', 'runPeriod', 'queryThreshold'];
const INDEXED_PLANS = ['IXSCAN', 'IDHACK'];
/**
* @typedef {Object} CurrentOp
* @property {?string} appName The identifier of the client application
* @property {string} op The type of operation e.g. 'update', 'insert', etc.
* @property {string} ns The namespace the operation targets
* @property {?string} planSummary The query plan for the operation
* @property {boolean} waitingForLock Whether the operation is waiting for a lock
*
* @see https://docs.mongodb.com/manual/reference/command/currentOp/#currentop-output-fields
*/
/**
* A utility class to simplify retrieving slow queries from Mongo.

@@ -27,3 +38,3 @@ */

assert(options.db, 'Must provide a valid DB reference');
this.db = options.db;

@@ -46,3 +57,4 @@ this.queryThreshold = 5;

* indexed: If this query was able to use an index or not,
* waitingForLock: True if the query is waiting for a lock, false otherwise
* waitingForLock: True if the query is waiting for a lock, false otherwise,
* appName: The client application responsible for this operation
* }]

@@ -71,9 +83,10 @@ * ```

var processed = _.map(inprog, (query) => {
var processed = _.map(inprog, (op) => {
return {
query,
fingerprint: fingerprint(query.query),
collection: query.ns ? query.ns.replace(/.*\./, '') : '(no collection)',
indexed: query.planSummary && (query.planSummary.indexOf('IXSCAN') !== -1),
waitingForLock: query.waitingForLock
query: op,
fingerprint: fingerprint(op.query),
collection: op.ns ? op.ns.replace(/.*\./, '') : '(no collection)',
indexed: op.planSummary && this.isIndexed(op),
waitingForLock: op.waitingForLock,
appName: op.appName
};

@@ -84,4 +97,14 @@ });

}
/**
* Given an operation with a planSummary, determines whether or not it's using an index.
*
* @param {CurrentOp} op
* @return {boolean} whether or not the given operation is using an index
*/
isIndexed(op) {
return INDEXED_PLANS.some((p) => op.planSummary.indexOf(p) !== -1);
}
}
module.exports = MongoSlowQueryChecker;
module.exports = MongoSlowQueryChecker;
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc