Skip to content

sanjorgek/sails-hook-mongoIndexes

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

59 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

sails-hook-mongoindexes

NPM Version NPM Downloads Build Status Code Climate Issue Count bitHound Overall Score bitHound Dependencies bitHound Dev Dependencies bitHound Code

Hook for sails and mongoDB

About

This hook allows us to write indexes for mongoDB

NPM

Use

Install

npm install sails-hook-mongoindexes

In config/connections.js

module.exports.connections = {
  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

module.exports.models = {
  connection: 'somethingMongodbServer',
  migrate: 'safe'
};

In models, example User.js

module.exports = {
  //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!

About

Hook for sails and mongoDB

Resources

License

Stars

Watchers

Forks

Packages

No packages published