Skip to content

Provides advanced mongo indexing options for sails.js (both v0.12 and v1.0) models that use the sails-mongo-* adapter.

License

Notifications You must be signed in to change notification settings

mohemohe/sails-hook-mongoat

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

22 Commits
 
 
 
 
 
 
 
 

Repository files navigation

DISCONTINUED

moved: https://github.com/mobilusoss/sails-hook-mongoat


sails-hook-mongoat

NPM version Build status Dependency Status

Provides advanced mongo indexing options for sails.js models that use the sails-mongo adapter.

Usage

npm i sails-hook-mongoat

Then simply add an 'indexes' array property to your sails model(s) that you want to add custom indexers on. This contains all your indexes.

Index properties:

  • attributes - an object with the attributes to index (can also be text indexes)
  • options (optional) - index options (see Mongo Index Options)

Examples

Creating a 'expires after' index

// MY MODEL WITH A DATE FIELD
module.exports = {
  attributes: {
    myDate: {
      type: 'date',
      required: true
    }
  },
  indexes: [
    {
      attributes: {
        myDate: 1
      },
      options: {
        expireAfterSeconds: 60  // expire 60s after myDate
      }
    }
  ]
};

Creating a composite unique index

// MY EVENTS MODEL
module.exports = {
  attributes: {
    event_id: {
      type: 'integer',
      required: true
    },
    match_id: {
      type: 'integer',
      required: true
    }
  },
  indexes: [
    //event & match composite index
    {
      attributes: {
        event_id: -1,    // desc
        match: 1         // asc
      },
      options: {
        unique: true
      }
    }
  ]
};

Maintained By

About

Provides advanced mongo indexing options for sails.js (both v0.12 and v1.0) models that use the sails-mongo-* adapter.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • JavaScript 100.0%