1.0.4 • Published 6 years ago

monoxide-auto-indexer v1.0.4

Weekly downloads
1
License
MIT
Repository
github
Last release
6 years ago

Monoxide-Auto-Indexer

Plugin for Monoxide to automatically manage MongoDB indexes.

var monoxide = require('monoxide');
var monoxideAutoIndexer = require('monoxide-auto-indexer');

monoxide
	.connect('mongodb://localhost/monoxide-test')
	.use(monoxideAutoIndexer())
	.models.users.hook('autoIndexer.build', (hookDone, index) => {
		console.log('Created index', index);
		hookDone();
	});

See the testkit for more complex examples.

API

AutoIndxer (main module)

The module exports a function factory which can take the following settings:

SettingTypeDefaultDescription
dryRunBooleanfalseDon't actually create the indexes in Mongo, just act as though we did
modelFilterFunction(accepts all models)Function to filter collections / models - by default all are used
indexThrottleNumber1000*60 (60 seconds)How often in milliseconds to throttle index queries
indexResetOnBuildBooleantrueWhether to reset the index cache when building a new index
indexCreateErrorsBooleanfalsePass on index creation errors to the initial query handler, if false creation errors are ignored
sortIndexesBooleanfalseSort the created indexes alphabetically, this is easier to read but has a slight performance hit

Emits autoIndexer.query (as (indexes)) when querying an index and autoIndexer.build (as (index, mongoSpec)) when building a new index.

AutoIndexer.clean()

Utility function to remove unused indexes. Ideally this function should be called at an hour the system is not under load.

This function can take the following settings:

SettingTypeDefaultDescription
modelFilterFunction(accepts all models)Function to filter collections / models - by default all are used
indexFilterFunction(rejects only _id fields)Function to filter index selection from cleaning
dryRunBooleanfalseDon't actually remove indexes, just report on what would be removed
hitMinNumber100The minimum number of hits for an index to be retained

Emits autoIndexer.clean with the single argument being the index that will be removed.

DEBUGGING

Enable the DEBUG=monoxide-auto-indexer flag to see verbose information about keys being cleaned.

1.0.4

6 years ago

1.0.3

6 years ago

1.0.2

6 years ago

1.0.1

6 years ago

1.0.0

6 years ago

0.0.0

6 years ago