-
Notifications
You must be signed in to change notification settings - Fork 72
Adding Custom Index to ForerunnerDB
Rob Evans edited this page Feb 25, 2016
·
2 revisions
If you are a developer that wishes to create a custom index type to support different indexing strategies in ForerunnerDB you can write your index code and then register the index in ForerunnerDB's index registry.
Your index should be an instantiatable object and accept the arguments:
// Import the shared object so we can register with ForerunnerDB at the end of
// our code.
Shared = require('./Shared');
/**
* Create the index.
* @param {Object} keys The object with the keys that the user wishes the index
* to operate on.
* @param {Object} options Can be undefined, if passed is an object with arbitrary
* options keys and values.
* @param {Collection} collection The collection the index should be created for.
*/
var MyNewIndexClass = function (keys, options, collection) { ... }
At the end of your class source code, register the index type with ForerunnerDB via:
Shared.index.myNewIndexType = MyNewIndexClass;
When the user asks to create an index with your index type, ForerunnerDB will instantiate the class and pass the keys, options and collection arguments to it.
You can use your new index in the normal way e.g.:
db.collection('myCollection').ensureIndex({
name: 1
}, {
type: 'myNewIndexType'
});
The ensureIndex() method arguments 1 and 2 are the objects your index class gets passed as keys and options arguments.