Access JavaScript objects from multiple indexes.
CoffeeScript JavaScript
Switch branches/tags
Nothing to show
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.


MultiIndex is a node.js module allowing you to index JavaScript objects. You can dynamically add any numbers of indexes to your objects.

How to use MultiIndex

A Multi-indexed objects store is created like this:

    var MultiIndex = require('MultiIndex');
    var util = require('util');

    var store = new MultiIndex;

You can add an object into the store using the add(obj, [indexes]) function.

    var obj1 = {
      , connectionid: 1
      , username: 'jo'
      , group: 'testers'
      , city: 'montreal'
    // add obj1 into store but don't index it yet = store.add(obj1);

Object can be indexed at insersion time or later. You can index an object at any time with the index(id, indexes) function.

    // index obj1 by username, group, connectionid and city
    store.index(, {
        username    : obj1.username
      , group       :
      , connectionid: obj1.connectionid
      , city        :

    var obj2 = {
      , connectionid: 2
      , username: 'hellen'
      , group: 'tech writer'
      , city: 'montreal'
    // add obj2 into store and index it = store.add(obj2, {
        username    : obj2.username
      , group       :
      , connectionid: obj2.connectionid
      , city        :

There are two getter functions. One is to get one single object and the other is to get all objects correspoding to the provided indexes.

var obj = getOne(indexes)

var arrObjs = get(indexes)
    var obj = store.getOne({username:'jo'});
    if (obj) {

Iterates through store for objects indexed by indexes.

    store.forEach({city:'montreal'}, function (obj) {
        console.log('sending a message to user:'+obj.username);
        // ...

Object can be removed with function remove(indexes)

    store.remove({connectionid: connectionid});


see under doc/


  • publish with npm
  • add function to remove some indexes