Provides advanced MongoDB indexing options for Sails.js models that use the sails-mongo adapter.
npm i git+ssh://git@github.com/fpm-git/sails-hook-mongoat.gitThen 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)
// 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
},
}],
};// MY EVENTS MODEL
module.exports = {
attributes: {
event_id: {
type: 'integer',
required: true,
},
match_id: {
type: 'integer',
required: true,
},
},
indexes: [{
// Index on both `event_id` and `match`.
attributes: {
event_id: -1, // desc
match: 1, // asc
},
options: {
unique: true,
},
}],
};Sometimes it might be desireable to run migrations in safe mode, something which is automatically prevented by default. In such scenarios, switching to drop or alter may not entirely be an option.
For these cases, the mongoat.forceUpdate config value may be set to a truthy value, forcing the hook to attempt updates regardless of model migration preference.
This flag may be set conveniently through the commandline when launching your Sails app:
# With Sails running in console mode:
$ sails console --mongoat.forceUpdate
# Or run Sails without the REPL:
$ sails lift --mongoat.forceUpdate
# Or run Sails directly:
$ node ./node_modules/.bin/sails lift --mongoat.forceUpdate