sails-hook-mongoindexes
Hook for sails and mongoDB
About
This hook allows us to write indexes for mongoDB
Use
Install
npm install sails-hook-mongoindexes
In config/connections.js
moduleexportsconnections = somethingMongodbServer: //You need sails-mongo adapter to work adapter: 'sails-mongo' host: 'localhost' port: 27017 // user: 'username', // password: 'password', database: 'test' //You can configure multiple databases with the same format othermongoDBServer:{}
In config/models.js
moduleexportsmodels = connection: 'somethingMongodbServer' migrate: 'safe';
In models, example User.js
moduleexports = //Put names on your fields atributes: name: 'string' lastName: 'string' userName: 'string' password: 'string' //And here your indexes for that fields index: //Now you can index unique fields ind:userName:1 ops: unique: true required: true //Agruop fields ind:name:1 lastName:1 ops: unique: true w:1 //Or simply required ind:password:1 ops: required: true w:1 ;
Thats all!